Class FlexibleJsonModel
JsonAnyGetter and JsonAnySetter feature to get and set these "extra fields" in a property
named extraFields.
The general use case for this "extra fields" is when a service or application proxies data from a canonical source where we don't want or need to know about every individual field, but where we still want to capture those fields, so we can store, display, etc. them. For example, a remote service that has a large number of properties, and we only care about a few of them, but we might want to store all of them for analytics, debugging, etc.
This implementation intentionally does not define equals or hashCode methods, which means the
extra fields will not be included in equality checks unless subclasses choose to include them. It does, however,
include a default toString method that will print out the extra fields. Whether to include extra fields
in equality checks depends heavily on the use case, so subclasses must decide for themselves. In addition, many
times simple data holder objects don't need to be compared so don't need equals or hashCode.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the "extra" fields that were not explicitly defined as properties when this object was de-serialized from JSON.voidsetExtraFields(String key, Object value) Add an "extra" field when de-serializing from JSON.toString()
-
Field Details
-
extraFields
-
-
Constructor Details
-
FlexibleJsonModel
public FlexibleJsonModel()
-
-
Method Details
-
getExtraFields
Returns the "extra" fields that were not explicitly defined as properties when this object was de-serialized from JSON.- Returns:
- the extra fields
-
setExtraFields
Add an "extra" field when de-serializing from JSON.- Parameters:
key- the extra field namevalue- the value of the extra field
-
toString
-