Package org.apache.juneau.swap
Class AutoObjectSwap<T>
java.lang.Object
org.apache.juneau.swap.ObjectSwap<T,Object>
org.apache.juneau.swap.AutoObjectSwap<T>
- Type Parameters:
T
- The normal class type.
A dynamic object swap based on reflection of a Java class that converts Objects to serializable objects.
Looks for methods on the class that can be called to swap-in surrogate objects before serialization and swap-out surrogate objects after parsing.
Valid surrogate objects
Valid swap methods (S = Swapped type)
public S swap()public S swap(BeanSession)public S toObject()public S toObject(BeanSession)
Valid unswap methods (N = Normal type, S = Swapped type)
public static N unswap(S)public static N unswap(BeanSession, S)public static N fromObject(S)public static N fromObject(BeanSession, S)public static N create(S)public static N create(BeanSession, S)public N(S)
Classes are ignored if any of the following are true:
- Classes annotated with
@BeanIgnore
. - Non-static member classes.
Members/constructors are ignored if any of the following are true:
- Members/constructors annotated with
@BeanIgnore
. - Deprecated members/constructors.
See Also:
-
Field Summary
Fields inherited from class org.apache.juneau.swap.ObjectSwap
NULL
-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectSwap<?,
?> find
(BeanContext bc, ClassInfo ci) Inspects the specified class and returns a swap of this type if possible.swap
(BeanSession session, Object o) If this transform is to be used to serialize non-serializable objects, it must implement this method.unswap
(BeanSession session, Object f, 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.swap.ObjectSwap
forMediaTypes, forMediaTypes, getNormalClass, getSwapClass, getSwapClassMeta, isNormalObject, isSwappedObject, match, swap, toString, unswap, withTemplate, withTemplate
-
Method Details
-
find
Inspects the specified class and returns a swap of this type if possible.- Parameters:
bc
- The bean context to use for looking up annotations.ci
- The class to return a swap on.- Returns:
- An object swap instance, or
null if one could not be created.
-
swap
Description copied from class:ObjectSwap
If 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
-
Collection
containing anything on this list. -
Map
containing anything on this list. - A java bean with properties of anything on this list.
- An array of anything on this list.
- Overrides:
swap
in classObjectSwap<T,
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:ObjectSwap
If this transform is to be used to reconstitute objects that aren't true Java beans, it must implement this method.- Overrides:
unswap
in classObjectSwap<T,
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.f
- 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
-