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.
The following types are currently provided:
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
This repository is made available under the Apache 2.0 License.