Class AutoListSwap<T>

java.lang.Object
org.apache.juneau.swap.ObjectSwap<T,List<?>>
org.apache.juneau.swap.AutoListSwap<T>
Type Parameters:
T - The normal class type.

public class AutoListSwap<T> extends ObjectSwap<T,List<?>>
A dynamic object swap based on reflection of a Java class that converts objects to Lists.

Looks for methods on the class that can be called to swap-in surrogate List objects before serialization and swap-out surrogate List objects after parsing.

Valid surrogate objects
  • Any subclass of List
Valid swap methods (S = Swapped type)
  • public S toList()
  • public S toList(BeanSession)
  • public S toJsonList()
  • public S toJsonList(BeanSession)
Valid unswap methods (N = Normal type, S = Swapped type)
  • public static N fromList(S)
  • public static N fromList(BeanSession, S)
  • public static N fromJsonList(S)
  • public static N fromJsonList(BeanSession, S)
  • public static N create(S)
  • public static N create(BeanSession, S)
  • public static N valueOf(S)
  • public static N valueOf(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)
      Look for constructors and methods on this class and construct a dynamic swap if it's possible to do so.
      Parameters:
      bc - The bean context to use for looking up annotations.
      ci - The class to try to constructor a dynamic swap on.
      Returns:
      An object swap instance, or null if one could not be created.
    • swap

      public List<?> 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,List<?>>
      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, List<?> o, 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,List<?>>
      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 type GregorianCalendar.
      This may be null if the parser cannot make this determination.
      Returns:
      The narrowed object.
      Throws:
      ParseException