Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 2.28 KB

README.md

File metadata and controls

68 lines (49 loc) · 2.28 KB

Autorelease

Human Readable Types

Build Status

This repository provides a collection of useful types that can be deserialized from human-readable strings. These types can be particularly useful for use in POJOs deserialized from configuration files where legibility is important.

human-readable-types

The following types are currently provided:

Example Usage

Maven artifacts are published to JCenter. Example Gradle dependency configuration:

repositories {
    jcenter()
}

dependencies {
    compile "com.palantir.human-readable-types:human-readable-types:$version"
}

Using these types alongside Jackson and Immutables might look something like:

package com.palantir.example;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.palantir.humanreadabletypes.HumanReadableByteCount;
import com.palantir.humanreadabletypes.HumanReadableDuration;
import org.immutables.value.Value;

@Value.Immutable
@JsonDeserialize(as = ImmutableExampleConfiguration.class)
public abstract class ExampleConfiguration {
    
    @JsonProperty("maximum-connect-timeout")
    public abstract HumanReadableDuration getMaximumConnectTimeout();
    
    @JsonProperty("maximum-file-size")
    public abstract HumanReadableByteCount getMaximumFileSize();
}

If this class were deserialized from some YAML file this may look something like:

# example.yml
maximum-connect-timeout: 2 minutes
maximum-file-size: 10 mibibytes

License

This repository is made available under the Apache 2.0 License.