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.

public class AutoObjectSwap<T> extends ObjectSwap<T,Object>
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:
  • Method Details

    • find

      public static ObjectSwap<?,?> find(BeanContext bc, ClassInfo ci)
      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

      public Object swap(BeanSession session, Object o) throws SerializeException
      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 class ObjectSwap<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

      public T unswap(BeanSession session, Object f, ClassMeta<?> hint) throws ParseException
      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 class ObjectSwap<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 type GregorianCalendar.
      This may be null if the parser cannot make this determination.
      Returns:
      The narrowed object.
      Throws:
      ParseException