Class SurrogateSwap<T,F>

java.lang.Object
org.apache.juneau.swap.ObjectSwap<T,F>
org.apache.juneau.swap.SurrogateSwap<T,F>
Type Parameters:
T - The class type that this transform applies to.
F - The transformed class type.

public class SurrogateSwap<T,F> extends ObjectSwap<T,F>
Specialized ObjectSwap for Surrogate classes.
See Also:
  • Constructor Details

    • SurrogateSwap

      protected SurrogateSwap(Class<T> forClass, Constructor<F> constructor, Method unswapMethod)
      Constructor.
      Parameters:
      forClass - The normal class.
      constructor - The constructor on the surrogate class that takes the normal class as a parameter.
      unswapMethod - The static method that converts surrogate objects into normal objects.
  • Method Details

    • findObjectSwaps

      public static List<SurrogateSwap<?,?>> findObjectSwaps(Class<?> c, BeanContext bc)
      Given the specified surrogate class, return the list of object swaps.

      A transform is returned for each public 1-arg constructor found. Returns an empty list if no public 1-arg constructors are found.

      Parameters:
      c - The surrogate class.
      bc - The bean context to use for looking up annotations.
      Returns:
      The list of object swaps that apply to this class.
    • swap

      public F swap(BeanSession session, T 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,F>
      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, F 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,F>
      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