Skip to content

palantir/human-readable-types

Repository files navigation

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.