Package org.apache.juneau.bean.hal
Class HalLinkOrArraySwap
java.lang.Object
org.apache.juneau.marshall.swap.spi.ObjectSwap<Object,Object>
org.apache.juneau.bean.hal.HalLinkOrArraySwap
Per-property
ObjectSwap applied to HAL _links maps so that each map entry round-trips
as either a single HalLink (JSON object) or a HalLinkArray (JSON array) per the spec.
The swap operates on the whole Map<String,Object> bean property and walks the entries:
- On serialize (
swap(org.apache.juneau.marshall.MarshallingSession, java.lang.Object)): identity - values that areHalLinkorHalLinkArrayalready serialize as the correct JSON shape. - On parse (
unswap(org.apache.juneau.marshall.MarshallingSession, java.lang.Object, org.apache.juneau.marshall.ClassMeta<?>)): each value that came back as a parsed list is converted toHalLinkArray; each value that came back as a parsed map is converted toHalLink. nullinput ⇒nulloutput.
Mirrors BooleanOrSchemaSwap in juneau-bean-jsonschema (the entry-disambiguation idea), with
iteration over map entries instead of operating on a single value.
-
Field Summary
Fields inherited from class org.apache.juneau.marshall.swap.spi.ObjectSwap
NULL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionswap(MarshallingSession session, Object o) If this transform is to be used to serialize non-serializable objects, it must implement this method.unswap(MarshallingSession session, Object o, ClassMeta<?> hint) If this transform is to be used to reconstitute objects that aren't true Java beans, it must implement this method.Methods inherited from class org.apache.juneau.marshall.swap.spi.ObjectSwap
forMediaTypes, forMediaTypes, getNormalClass, getSwapClass, getSwapClassMeta, isNormalObject, isSwappedObject, match, swap, toString, unswap, withTemplate, withTemplate
-
Constructor Details
-
HalLinkOrArraySwap
public HalLinkOrArraySwap()
-
-
Method Details
-
swap
Description copied from class:ObjectSwapIf this transform is to be used to serialize non-serializable objects, it must implement this method.The object must be converted into one of the following serializable types:
-
String -
Number -
Boolean -
Collectioncontaining anything on this list. -
Mapcontaining anything on this list. - A java bean with properties of anything on this list.
- An array of anything on this list.
- Overrides:
swapin classObjectSwap<Object,Object> - Parameters:
session- The bean session to use to get the class meta. This is always going to be the same bean context that created this swap.o- The object to be transformed.- Returns:
- The transformed object.
- Throws:
SerializeException
-
-
unswap
Description copied from class:ObjectSwapIf this transform is to be used to reconstitute objects that aren't true Java beans, it must implement this method.- Overrides:
unswapin classObjectSwap<Object,Object> - Parameters:
session- The bean session to use to get the class meta. This is always going to be the same bean context that created this swap.o- The transformed object.hint- If possible, the parser will try to tell you the object type being created. For example, on a serialized date, this may tell you that the object being created must be of typeGregorianCalendar.
This may benull if the parser cannot make this determination.- Returns:
- The narrowed object.
- Throws:
ParseException
-