Class FlexibleJsonModel
- java.lang.Object
-
- org.kiwiproject.json.FlexibleJsonModel
-
public abstract class FlexibleJsonModel extends Object
This class can be used as a base class for situations where there may be additional/unknown properties in a JSON string that don't have a corresponding property in the class being de-serialized into. It uses Jackson'sJsonAnyGetterandJsonAnySetterfeature to get and set these "extra fields" in a property namedextraFields.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
equalsorhashCodemethods, which means the extra fields will not be included in equality checks unless subclasses choose to include them. It does, however, include a defaulttoStringmethod 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 needequalsorhashCode.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,Object>extraFields
-
Constructor Summary
Constructors Constructor Description FlexibleJsonModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Object>getExtraFields()Returns 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.
-