A - The type of the serialized element representation, e.g. JsonElement.T - The type of the serialized aggregate representation, e.g. JsonObject. For recursive
serialized forms, like JSON, this may be the same as or a subtype of A, but
for non-recursive serialized forms this is may be an unrelated type.public interface ValueSerializer<A,T>
The values passed to the serialize* methods fulfill the constraints of their
corresponding types. However, in general, the serialized form passed to the deserialize*
methods may not fulfill the constraints, nor even be a correct representation of the platform type.
If a serializer cannot deserialize a value of the correct platform type as determined by
SerializableType.cast(Object), then it shall throw a ValueDeserializationException
containing the element that could not be converted and the erased class type it was trying to convert to.
However, a serializer is not expected to produce values that satisfy the ancillary constraints of
the passed type. Client code is responsible for coercing deserialized values into a form consistent
with its type's constraints.
The methods of this interface which operate on serialized elements or targets may consume or otherwise mutate the serialized representations passed to them.
| Modifier and Type | Method and Description |
|---|---|
void |
addElement(String name,
A elem,
T target,
String comment)
Aggregates a serialized value, associated with the given key, into the target.
|
void |
addSubElement(String name,
T elem,
T target,
String comment)
Aggregates an existing target, associated with the given key, into the target as a sub-target.
|
boolean |
deserializeBoolean(A elem,
BooleanSerializableType type)
Converts the serialized form to a boolean.
|
String |
deserializeEnum(A elem,
EnumSerializableType type)
Converts the serialized form to a enumerated value.
|
<E> List<E> |
deserializeList(A elem,
ListSerializableType<E> type)
Converts the serialized form to a list of values.
|
<V> Map<String,V> |
deserializeMap(A elem,
MapSerializableType<V> type)
Converts the serialized form to a map.
|
BigDecimal |
deserializeNumber(A elem,
DecimalSerializableType type)
Converts the serialized form to a number.
|
Map<String,Object> |
deserializeRecord(A elem,
RecordSerializableType type)
Converts the serialized form to a record.
|
String |
deserializeString(A elem,
StringSerializableType type)
Converts the serialized form to a string.
|
Iterator<Map.Entry<String,A>> |
elements(T target)
Extracts an
Iterator over all aggregated key-value pairs in the given target. |
T |
newTarget()
Creates a new, empty aggregate target.
|
T |
readTarget(InputStream in)
Reads an aggregate target from the given input stream.
|
A |
serializeBoolean(boolean value,
BooleanSerializableType type)
Converts a boolean into the serialized form.
|
A |
serializeEnum(String value,
EnumSerializableType type)
Converts a enumerated string into the serialized form.
|
<E> A |
serializeList(List<E> value,
ListSerializableType<E> type)
Converts a list into the serialized form.
|
<V> A |
serializeMap(Map<String,V> value,
MapSerializableType<V> type)
Converts a map into the serialized form.
|
A |
serializeNumber(BigDecimal value,
DecimalSerializableType type)
Converts a number into the serialized form.
|
A |
serializeRecord(Map<String,Object> value,
RecordSerializableType type)
Converts a record into the serialized form.
|
A |
serializeString(String value,
StringSerializableType type)
Converts a string into the serialized form.
|
Iterator<Map.Entry<String,A>> |
subElements(A elem)
Extracts an
Iterator over all aggregated key-value pairs in the given sub-target element. |
void |
writeTarget(T target,
OutputStream out)
Writes a aggregate target to the given output stream.
|
A serializeBoolean(boolean value, BooleanSerializableType type)
value - The boolean value.type - The type of the boolean value.boolean deserializeBoolean(A elem, BooleanSerializableType type) throws ValueDeserializationException
elem - The serialized form.type - The type of the boolean value.ValueDeserializationException - If the serialized form cannot be converted into an object of
the correct platform type.A serializeNumber(BigDecimal value, DecimalSerializableType type)
value - The numeric value.type - The type of the numeric value.BigDecimal deserializeNumber(A elem, DecimalSerializableType type) throws ValueDeserializationException
elem - The serialized form.type - The type of the numeric value.ValueDeserializationException - If the serialized form cannot be converted into an object of
the correct platform type.A serializeString(String value, StringSerializableType type)
value - The string value.type - The type of the string value.String deserializeString(A elem, StringSerializableType type) throws ValueDeserializationException
elem - The serialized form.type - The type of the string value.ValueDeserializationException - If the serialized form cannot be converted into an object of
the correct platform type.A serializeEnum(String value, EnumSerializableType type)
value - The enum value.type - The type of the enum value.String deserializeEnum(A elem, EnumSerializableType type) throws ValueDeserializationException
elem - The serialized form.type - The type of the enumerated value.ValueDeserializationException - If the serialized form cannot be converted into an object of
the correct platform type.<E> A serializeList(List<E> value, ListSerializableType<E> type)
value - The list value.type - The type of the list value.<E> List<E> deserializeList(A elem, ListSerializableType<E> type) throws ValueDeserializationException
elem - The serialized form.type - The type of the list value.ValueDeserializationException - If the serialized form cannot be converted into an object of
the correct platform type.<V> A serializeMap(Map<String,V> value, MapSerializableType<V> type)
value - The map value.type - The type of the map value.<V> Map<String,V> deserializeMap(A elem, MapSerializableType<V> type) throws ValueDeserializationException
elem - The serialized form.type - The type of the map value.ValueDeserializationException - If the serialized form cannot be converted into an object of
the correct platform type.A serializeRecord(Map<String,Object> value, RecordSerializableType type)
value - The record value.type - The type of the record value.Map<String,Object> deserializeRecord(A elem, RecordSerializableType type) throws ValueDeserializationException
elem - The serialized form.type - The type of the record value.ValueDeserializationException - If the serialized form cannot be converted into an object of
the correct platform type.void addElement(String name, A elem, T target, @Nullable String comment)
name - The key with which to associate the value.elem - The serialized value.target - The target aggregate.comment - an optional comment associated with the element.void addSubElement(String name, T elem, T target, @Nullable String comment)
name - The key with which to associate the sub-target.elem - The sub-target.target - The target aggregate.comment - an optional comment associated with the elementIterator<Map.Entry<String,A>> elements(T target)
Iterator over all aggregated key-value pairs in the given target.target - The target.Iterator<Map.Entry<String,A>> subElements(A elem) throws ValueDeserializationException
Iterator over all aggregated key-value pairs in the given sub-target element.elem - The serialized sub-target element.ValueDeserializationException - If elem does not represent a sub-target.void writeTarget(T target, OutputStream out) throws IOException
target - The target.out - The output stream.IOException - If an IO error occurs while writing to the stream.T readTarget(InputStream in) throws ValueDeserializationException, IOException
in - The input stream.ValueDeserializationException - If a target cannot be read from the stream.IOException - If an IO error occurs while reading from the stream.T newTarget()