Class JsonCodec
What the JSON codecs the build generates call: typed reads that refuse a value with a message naming where it was, and the date form.
A controller that returns or accepts one of the application's own classes --
an entity, a DTO -- gets a codec written for that class at build time, the way
Jackson would map it at run time: its fields by name, @JsonProperty renaming
one and @JsonIgnore leaving one out. The codec calls these methods, so
nothing here is looked up by name or reflected on, and a server with no such
route never links this class.
A refused value is an IllegalArgumentException whose message says where in
the body it was and what was expected -- $.items[2].due: expected a number or an ISO-8601 date, got true -- which the generated router answers with 400.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHow deep a codec follows one object into another before it refuses: past any real document, and short of the stack a cycle between two objects would otherwise exhaust. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonCodec.Pathenter(JsonCodec.Path at, String name, int index) The path of membernameor elementindexofat, oratitself when neither is given -- where a codec is when it starts reading an object or an array.static IllegalArgumentExceptionmismatch(JsonCodec.Path at, String name, int index, String expected, Object got) The refusal ofgotat membernameor elementindexofat; pass null and -1 foratitself.static booleanreadBoolean(Object json, JsonCodec.Path at, String name, int index) trueorfalse.static byte[]readBytes(Object json, JsonCodec.Path at, String name, int index) Base64 text, or null.static charreadChar(Object json, JsonCodec.Path at, String name, int index) A string of one character.static DatereadDate(Object json, JsonCodec.Path at, String name, int index) Milliseconds since the epoch -- the formwriteDate(Date, ByteSink)writes and the app's mapper reads -- or an ISO-8601 date, with or without a time and an offset; one without an offset is UTC.static doublereadDouble(Object json, JsonCodec.Path at, String name, int index) Any number.static longreadLong(Object json, JsonCodec.Path at, String name, int index, long min, long max) A whole number betweenminandmax.static StringreadString(Object json, JsonCodec.Path at, String name, int index) A string, or null.static IllegalStateExceptionRefuses an object nested pastMAX_DEPTH, which in a response means a cycle: two objects that reach each other through their fields.static voidA date as milliseconds since the epoch, as Jackson writes one by default and as the app's generated mapper reads it back.
-
Field Details
-
MAX_DEPTH
public static final int MAX_DEPTHHow deep a codec follows one object into another before it refuses: past any real document, and short of the stack a cycle between two objects would otherwise exhaust.- See Also:
-
-
Method Details
-
enter
The path of membernameor elementindexofat, oratitself when neither is given -- where a codec is when it starts reading an object or an array. -
mismatch
public static IllegalArgumentException mismatch(JsonCodec.Path at, String name, int index, String expected, Object got) The refusal ofgotat membernameor elementindexofat; pass null and -1 foratitself. -
tooDeep
Refuses an object nested pastMAX_DEPTH, which in a response means a cycle: two objects that reach each other through their fields. -
readLong
public static long readLong(Object json, JsonCodec.Path at, String name, int index, long min, long max) A whole number betweenminandmax. A number with a fraction is refused rather than cut short. -
readDouble
Any number. -
readBoolean
trueorfalse. -
readChar
A string of one character. -
readString
A string, or null. -
readBytes
Base64 text, or null. -
readDate
Milliseconds since the epoch -- the formwriteDate(Date, ByteSink)writes and the app's mapper reads -- or an ISO-8601 date, with or without a time and an offset; one without an offset is UTC. Null stays null. -
writeDate
-