Class AutoNumberSwap<T>

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

public class AutoNumberSwap<T> extends ObjectSwap<T,Number>
A dynamic object swap based on reflection of a Java class that converts Objects to Number serializable objects.

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

Valid surrogate objects
  • Any subclass of Number
  • Any number primitive
Valid swap methods (S = Swapped type)
  • public S toNumber()
  • public S toNumber(BeanSession)
  • public S toInteger()
  • public S toInteger(BeanSession)
  • public S toInt()
  • public S toInt(BeanSession)
  • public S toLong()
  • public S toLong(BeanSession)
  • public S toFloat()
  • public S toFloat(BeanSession)
  • public S toDouble()
  • public S toDouble(BeanSession)
  • public S toShort()
  • public S toShort(BeanSession)
  • public S toByte()
  • public S toByte(BeanSession)
Valid unswap methods (N = Normal type, S = Swapped type)
  • public static N fromInteger(S)
  • public static N fromInteger(BeanSession, S)
  • public static N fromInt(S)
  • public static N fromInt(BeanSession, S)
  • public static N fromLong(S)
  • public static N fromLong(BeanSession, S)
  • public static N fromFloat(S)
  • public static N fromFloat(BeanSession, S)
  • public static N fromDouble(S)
  • public static N fromDouble(BeanSession, S)
  • public static N fromShort(S)
  • public static N fromShort(BeanSession, S)
  • public static N fromByte(S)
  • public static N fromByte(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 Number 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,Number>
      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, Number 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,Number>
      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