You just need to play with it the other day, and struggled with it for several hours, trying @Category
and others methods, until you find this: you can create a property of type Splittable
, which represents the base transport type, which has some encoding for Boolean / Lines / Lists /Cards. In my case, I know some type of enveloping that passes through the wire during development and based on some other property, there can be any number of other auto-declarations in another field.
You donโt even need to know the type of another bean at compile time, you can get the values โโusing the Splittable
methods, but when using autoblocks, itโs nice to define data that is wrapped anyway.
interface Envelope { String getStatus(); String getDataType(); Splittable getData(); }
(Setters may be desirable if you are sending data, as well as receiving - encoding the bean in "Split for sending in an envelope, even easier than decoding it"
The JSON sent over the cable is decoded (possibly using AutoBeanCodex
) into an Envelope
type, and after you decide which type should get out of the getData()
method, call something like this to get a nested object
SpecificNestedBean bean = AutoBeanCodex.decode(factory, SpecificNestedBean.class, env.getData()).as();
The Envelope
type and nested types (in the factory
above) do not even have to be the same AutoBeanFactory
types. This can allow you to ignore reading / writing envelopes from a universal transport instance and use for each dataType
property the value of a specific factory to decode the data model (and nested models).
source share