Package hydra.ext.json
Class JsonDecoding
- java.lang.Object
-
- hydra.ext.json.JsonDecoding
-
public abstract class JsonDecoding extends java.lang.Object
Decoding functions for Hydra's native JSON values which are intended for use in Java. Decoding failures result in Java exceptions rather than failure flows.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JsonDecoding.JsonDecodingException
-
Constructor Summary
Constructors Constructor Description JsonDecoding()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
decodeBoolean(Value json)
Decode a boolean value from JSON.static double
decodeDouble(Value json)
Decode a double value from JSON.static <A> A
decodeEnum(java.util.Map<java.lang.String,A> values, Value json)
Decode an enumerated value from JSON.static float
decodeFloat(Value json)
Decode a float value from JSON.static int
decodeInteger(Value json)
Decode an integer value from JSON.static <A> java.util.List<A>
decodeList(java.util.function.Function<Value,A> mapping, Value json)
Decode a list from JSON.static <A> java.util.List<A>
decodeListField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode a list field from JSON.static <A> java.util.List<A>
decodeListField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode a list field from JSON.static double
decodeNumber(Value json)
Decode a number from JSON.static java.util.Map<java.lang.String,Value>
decodeObject(Value json)
Decode an object (key/value map) from JSON.static Opt<java.lang.Boolean>
decodeOptionalBooleanField(Name name, Value json)
Decode an optional boolean-valued field from JSON.static Opt<java.lang.Boolean>
decodeOptionalBooleanField(java.lang.String name, Value json)
Decode an optional boolean-valued field from JSON.static Opt<java.lang.Double>
decodeOptionalDoubleField(Name name, Value json)
Decode an optional double-valued field from JSON.static Opt<java.lang.Double>
decodeOptionalDoubleField(java.lang.String name, Value json)
Decode an optional double-valued field from JSON.static <A> Opt<A>
decodeOptionalField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode an optional field from JSON.static <A> Opt<A>
decodeOptionalField(Name name, java.util.function.Function<Value,A> mapping, Value json, A defaultValue)
Decode an optional field from JSON.static <A> Opt<A>
decodeOptionalField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode an optional field from JSON.static <A> Opt<A>
decodeOptionalField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json, A defaultValue)
Decode an optional field from JSON.static Opt<java.lang.Integer>
decodeOptionalIntegerField(Name name, Value json)
Decode an optional integer-valued field from JSON.static Opt<java.lang.Integer>
decodeOptionalIntegerField(java.lang.String name, Value json)
Decode an optional integer-valued field from JSON.static <A> Opt<java.util.Set<A>>
decodeOptionalSetField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode an optional set-valued field from JSON.static <A> Opt<java.util.Set<A>>
decodeOptionalSetField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode an optional set-valued field from JSON.static boolean
decodeRequiredBooleanField(Name name, Value json)
Decode a required boolean-valued field from JSON.static boolean
decodeRequiredBooleanField(java.lang.String name, Value json)
Decode a required boolean-valued field from JSON.static <A> A
decodeRequiredField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode a required field from JSON.static <A> A
decodeRequiredField(Name name, java.util.function.Function<Value,A> mapping, Value json, A defaultValue)
Decode a required field from JSON.static <A> A
decodeRequiredField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode a required field from JSON.static <A> A
decodeRequiredField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json, A defaultValue)
Decode a required field from JSON.static int
decodeRequiredIntField(Name name, Value json)
Decode a required int32-valued field from JSON.static int
decodeRequiredIntField(java.lang.String name, Value json)
Decode a required int32-valued field from JSON.static <A> java.util.List<A>
decodeRequiredListField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode a required list-valued field from JSON.static <A> java.util.List<A>
decodeRequiredListField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode a required list-valued field from JSON.static <A> java.util.Set<A>
decodeSet(java.util.function.Function<Value,A> mapping, Value json)
Decode a set from JSON.static java.lang.String
decodeString(Value json)
Decode a string value from JSON.static java.util.List<java.lang.String>
decodeStringList(Value json)
Decode a list of string values from JSON.static <A> A
decodeUnion(java.util.Map<java.lang.String,java.util.function.Function<Value,A>> mappings, Value json)
Decode a union (injection) from JSON.static JsonDecoding.JsonDecodingException
unexpected(java.lang.String expected, Value actual)
Fail on an unexpected JSON value.
-
-
-
Method Detail
-
decodeList
public static <A> java.util.List<A> decodeList(java.util.function.Function<Value,A> mapping, Value json)
Decode a list from JSON.
-
decodeBoolean
public static boolean decodeBoolean(Value json)
Decode a boolean value from JSON.
-
decodeDouble
public static double decodeDouble(Value json)
Decode a double value from JSON.
-
decodeEnum
public static <A> A decodeEnum(java.util.Map<java.lang.String,A> values, Value json)
Decode an enumerated value from JSON.
-
decodeFloat
public static float decodeFloat(Value json)
Decode a float value from JSON.
-
decodeInteger
public static int decodeInteger(Value json)
Decode an integer value from JSON.
-
decodeListField
public static <A> java.util.List<A> decodeListField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode a list field from JSON.
-
decodeListField
public static <A> java.util.List<A> decodeListField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode a list field from JSON.
-
decodeNumber
public static double decodeNumber(Value json)
Decode a number from JSON.
-
decodeObject
public static java.util.Map<java.lang.String,Value> decodeObject(Value json)
Decode an object (key/value map) from JSON.
-
decodeOptionalBooleanField
public static Opt<java.lang.Boolean> decodeOptionalBooleanField(java.lang.String name, Value json)
Decode an optional boolean-valued field from JSON.
-
decodeOptionalBooleanField
public static Opt<java.lang.Boolean> decodeOptionalBooleanField(Name name, Value json)
Decode an optional boolean-valued field from JSON.
-
decodeOptionalDoubleField
public static Opt<java.lang.Double> decodeOptionalDoubleField(java.lang.String name, Value json)
Decode an optional double-valued field from JSON.
-
decodeOptionalDoubleField
public static Opt<java.lang.Double> decodeOptionalDoubleField(Name name, Value json)
Decode an optional double-valued field from JSON.
-
decodeOptionalField
public static <A> Opt<A> decodeOptionalField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json, A defaultValue)
Decode an optional field from JSON.
-
decodeOptionalField
public static <A> Opt<A> decodeOptionalField(Name name, java.util.function.Function<Value,A> mapping, Value json, A defaultValue)
Decode an optional field from JSON.
-
decodeOptionalField
public static <A> Opt<A> decodeOptionalField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode an optional field from JSON.
-
decodeOptionalField
public static <A> Opt<A> decodeOptionalField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode an optional field from JSON.
-
decodeOptionalIntegerField
public static Opt<java.lang.Integer> decodeOptionalIntegerField(java.lang.String name, Value json)
Decode an optional integer-valued field from JSON.
-
decodeOptionalIntegerField
public static Opt<java.lang.Integer> decodeOptionalIntegerField(Name name, Value json)
Decode an optional integer-valued field from JSON.
-
decodeOptionalSetField
public static <A> Opt<java.util.Set<A>> decodeOptionalSetField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode an optional set-valued field from JSON.
-
decodeOptionalSetField
public static <A> Opt<java.util.Set<A>> decodeOptionalSetField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode an optional set-valued field from JSON.
-
decodeRequiredBooleanField
public static boolean decodeRequiredBooleanField(java.lang.String name, Value json)
Decode a required boolean-valued field from JSON.
-
decodeRequiredBooleanField
public static boolean decodeRequiredBooleanField(Name name, Value json)
Decode a required boolean-valued field from JSON.
-
decodeRequiredField
public static <A> A decodeRequiredField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json, A defaultValue)
Decode a required field from JSON.
-
decodeRequiredField
public static <A> A decodeRequiredField(Name name, java.util.function.Function<Value,A> mapping, Value json, A defaultValue)
Decode a required field from JSON.
-
decodeRequiredField
public static <A> A decodeRequiredField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode a required field from JSON.
-
decodeRequiredField
public static <A> A decodeRequiredField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode a required field from JSON.
-
decodeRequiredIntField
public static int decodeRequiredIntField(java.lang.String name, Value json)
Decode a required int32-valued field from JSON.
-
decodeRequiredIntField
public static int decodeRequiredIntField(Name name, Value json)
Decode a required int32-valued field from JSON.
-
decodeRequiredListField
public static <A> java.util.List<A> decodeRequiredListField(java.lang.String name, java.util.function.Function<Value,A> mapping, Value json)
Decode a required list-valued field from JSON.
-
decodeRequiredListField
public static <A> java.util.List<A> decodeRequiredListField(Name name, java.util.function.Function<Value,A> mapping, Value json)
Decode a required list-valued field from JSON.
-
decodeSet
public static <A> java.util.Set<A> decodeSet(java.util.function.Function<Value,A> mapping, Value json)
Decode a set from JSON.
-
decodeString
public static java.lang.String decodeString(Value json)
Decode a string value from JSON.
-
decodeStringList
public static java.util.List<java.lang.String> decodeStringList(Value json)
Decode a list of string values from JSON.
-
decodeUnion
public static <A> A decodeUnion(java.util.Map<java.lang.String,java.util.function.Function<Value,A>> mappings, Value json)
Decode a union (injection) from JSON.
-
unexpected
public static JsonDecoding.JsonDecodingException unexpected(java.lang.String expected, Value actual)
Fail on an unexpected JSON value.
-
-