hollow
hollow copied to clipboard
Add Jackson module to allow serialization of HollowObjects
This Jackson module allows direct serialization of HollowObject
s using Jackson datamapper.
- It supports both the default and ergonomic generated APIs
- You can optionally preserve the original order of the fields, because reflection doesn't return methods in their declared order. Implemented by walking the class files to avoid coupling the module to a single consumer/API to get at the schema
- Single-value non-reference types are automatically expanded
The only situation where the serialized json won't match the original object is when a HollowObject
with more than one time, or a reference type, is used as a Map
key. In that case, we fall back to the default Jackson behavior of calling toString
on the object.
I couldn't see a logic place to put this in the documentation, and you might want this to be a separate artifact, rather than bundled with the json adapter, but felt like a good start.
🔜
I've asked for feedback from Drew and Paul. Thanks for your patience, Danny.
Hi @DanielThomas, in what scenario would you prefer this over the HollowRecordJsonStringifier
?
@PaulSandoz though there's no guarantee, it seems the order in the class file is the order as declared.
@dkoszewnik the objects in our model have the same shape as our API. For many of our APIs we return Hollow objects directly or objects composed into calculated values at runtime and have them serialize directly in Spring MVC responses.
A general concern i have is the Jackson JSON serializer is operating by reflecting over the generated API classes. This is likely to be fragile. The generated API is a representation on the schema (as are the POJOs on the producing side) and that representation could change.
It is the schema + data that should ideally be operated on. For example, see HollowRecordJsonStringifier
. Is there a reason that class cannot be used to produce JSON?