Interface DataFormat
- All Known Implementing Classes:
DomXmlDataFormat,JacksonJsonDataFormat,SerializableDataFormat
-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if this data format can map the provided Java Object.getCanonicalTypeName(Object value) Returns a data-format-specific canonical type name.getName()Returns the data format name.<T> TReads the internal representation of a data format to a java object of the desired class.<T> TReads the internal representation of a data format to a java object of the desired class.default <T> TreadValue(String value, String typeIdentifier, DeserializationTypeValidator validator) Reads the internal representation of a data format to a java object of the desired class, validating the resolved Java type before it is used for deserialization.writeValue(Object value) Writes a java object to a data format's internal data representation.
-
Method Details
-
getName
String getName()Returns the data format name. -
canMap
Returns true if this data format can map the provided Java Object.- Parameters:
parameter- the java object to check- Returns:
- true if this object can be mapped.
-
writeValue
Writes a java object to a data format's internal data representation.- Parameters:
value- object that is written into internal data representation- Returns:
- the data format's internal representation of that object
-
readValue
Reads the internal representation of a data format to a java object of the desired class.- Parameters:
value- the object to be readtypeIdentifier- the class to map the object to- Returns:
- a java object of the specified class that was populated with the input parameter
-
readValue
default <T> T readValue(String value, String typeIdentifier, DeserializationTypeValidator validator) Reads the internal representation of a data format to a java object of the desired class, validating the resolved Java type before it is used for deserialization.When
validatorisnull(the default, backward-compatible case), the default implementation delegates toreadValue(String, String)unchanged, preserving the behavior of existingDataFormatimplementations that do not override this method. Implementations that resolvetypeIdentifierto one or more concrete Java classes (e.g. via class loading or generic type construction) should override this method and invokeDeserializationTypeValidator.validate(String)for every resolved class before it is used, so thatnullis returned/an exception thrown instead of instantiating a disallowed type.When
validatoris non-nullbut this method is not overridden, the default implementation fails closed: it throws aValueMapperExceptioninstead of silently deserializing without validation. A worker that has opted intoDeserializationTypeValidatormust be able to rely on it actually being enforced; silently ignoring it would defeat its purpose. Implementations that cannot honor the validator at all (e.g. because they do not usetypeIdentifierfor class selection in the first place, such as native Java serialization) should override this method themselves and throw their own, more specific exception explaining why - seeSerializableDataFormatfor an example.- Parameters:
value- the object to be readtypeIdentifier- the class to map the object tovalidator- validates the class(es) thattypeIdentifierresolves to before they are used for deserialization; may benull, in which case no validation is performed- Returns:
- a java object of the specified class that was populated with the input parameter
- Throws:
ValueMapperException- ifvalidatoris non-nulland this method is not overridden
-
readValue
Reads the internal representation of a data format to a java object of the desired class.- Parameters:
value- the object to be readcls- a data-format-specific type identifier that describes the class to map to- Returns:
- a java object of the specified class that was populated with the input parameter
-
getCanonicalTypeName
Returns a data-format-specific canonical type name.
-