Class ObjectSwap<T,S> 
- Type Parameters:
- T- The normal form of the class.
- S- The swapped form of the class.
- Direct Known Subclasses:
- AutoListSwap,- AutoMapSwap,- AutoNumberSwap,- AutoObjectSwap,- EnumerationSwap,- FunctionalSwap,- IteratorSwap,- JsonSchema.BooleanOrSchemaArraySwap,- JsonSchema.BooleanOrSchemaSwap,- JsonSchema.JsonSchemaOrSchemaArraySwap,- JsonSchema.JsonTypeOrJsonTypeArraySwap,- MapSwap,- MatchResultSwap,- OpenApiUI,- ParsedReaderSwap,- StackTraceElementSwap,- StringSwap,- SurrogateSwap,- SwaggerUI
Description
 
For example, JSON does not have a standard representation for rendering dates.
 By defining a special Date swap and associating it with a serializer and parser, you can convert a
 Date object to a String during serialization, and convert that String object back into a
 Date object during parsing.
 
Swaps MUST declare a public no-arg constructor so that the bean context can instantiate them.
 
 
- <T>- The normal representation of an object.
- <S>- The swapped representation of an object.
Serializers use swaps to convert objects of type T into objects of type S, and on calls to
 BeanMap.get(Object).
 Parsers use swaps to convert objects of type S into objects of type T, and on calls to
 BeanMap.put(String,Object).
 Swap Class Type <S>
 
 For normal serialization, the swapped object representation of an object must be an object type that the serializers can natively convert to
 JSON (or language-specific equivalent).
 
The list of valid transformed types are as follows...
 
- 
      String
- 
      Number
- 
      Boolean
- 
      Collectioncontaining anything on this list.
- 
      Mapcontaining anything on this list.
- A java bean with properties of anything on this list.
- An array of anything on this list.
 For OpenAPI serialization, the valid swapped types also include 
Normal Class Type <T>
 The normal object representation of an object.
See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedConstructor.protectedObjectSwap(Class<T> normalClass, Class<?> swapClass) Constructor for when the normal and transformed classes are already known.
- 
Method SummaryModifier and TypeMethodDescriptionReturns the media types that this swap is applicable to.ObjectSwap<T,?> forMediaTypes(MediaType[] mediaTypes) Sets the media types that this swap is associated with.Returns the T class, the normalized form of the class.Returns the G class, the generalized form of the class.ClassMeta<?>getSwapClassMeta(BeanSession session) Returns theClassMetaof the transformed class type.booleanChecks if the specified object is an instance of the normal class defined on this swap.booleanChecks if the specified object is an instance of the swap class defined on this swap.intmatch(BeanSession session) Returns a number indicating how well this swap matches the specified session.swap(BeanSession session, T o) If this transform is to be used to serialize non-serializable objects, it must implement this method.swap(BeanSession session, T o, String template) Same asswap(BeanSession, Object), but can be used if your swap has a template associated with it.toString()unswap(BeanSession session, S f, ClassMeta<?> hint) If this transform is to be used to reconstitute objects that aren't true Java beans, it must implement this method.unswap(BeanSession session, S f, ClassMeta<?> hint, String template) Same asunswap(BeanSession, Object, ClassMeta), but can be used if your swap has a template associated with it.Returns additional context information for this swap.ObjectSwap<T,?> withTemplate(String template) Sets the template string on this swap.
- 
Field Details- 
NULLRepresents a non-existent object swap.
 
- 
- 
Constructor Details- 
ObjectSwapprotected ObjectSwap()Constructor.
- 
ObjectSwapConstructor for when the normal and transformed classes are already known.- Parameters:
- normalClass- The normal class (cannot be serialized).
- swapClass- The transformed class (serializable).
 
 
- 
- 
Method Details- 
forMediaTypesReturns the media types that this swap is applicable to.This method can be overridden to programmatically specify what media types it applies to. This method is the programmatic equivalent to the @Swap(mediaTypes)annotation.See Also:- Returns:
- The media types that this swap is applicable to, or null if it's applicable for all media types.
 
- 
withTemplateReturns additional context information for this swap.Typically this is going to be used to specify a template name, such as a FreeMarker template file name. This method can be overridden to programmatically specify a template value. This method is the programmatic equivalent to the @Swap(template)annotation.See Also:- Returns:
- Additional context information, or null if not specified.
 
- 
forMediaTypesSets the media types that this swap is associated with.See Also:- Parameters:
- mediaTypes- The media types that this swap is associated with.
- Returns:
- This object.
 
- 
withTemplateSets the template string on this swap.See Also:- Parameters:
- template- The template string on this swap.
- Returns:
- This object.
 
- 
matchReturns a number indicating how well this swap matches the specified session.Uses the MediaType.match(MediaType, boolean)method algorithm to produce a number whereby a larger value indicates a "better match". The idea being that if multiple swaps are associated with a given object, we want to pick the best one.For example, if the session media type is "text/json" , then the match values are shown below:- "text/json" =- 100,000 
- "*/json" =- 5,100 
- "*/*" =- 5,000 
- No media types specified on swap = 1 
- "text/xml" =- 0 
 - Parameters:
- session- The bean session.
- Returns:
- Zero if swap doesn't match the session, or a positive number if it does.
 
- 
swapIf 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
- 
      Collectioncontaining anything on this list.
- 
      Mapcontaining anything on this list.
- A java bean with properties of anything on this list.
- An array of anything on this 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:
- Exception- If a problem occurred trying to convert the output.
 
- 
      
- 
swapSame asswap(BeanSession, Object), but can be used if your swap has a template associated with it.- 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.
- template- The template string associated with this swap.
- Returns:
- The transformed object.
- Throws:
- Exception- If a problem occurred trying to convert the output.
 
- 
unswapIf this transform is to be used to reconstitute objects that aren't true Java beans, it must implement this method.- 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:
- Exception- If this method is not implemented.
 
- 
unswapSame asunswap(BeanSession, Object, ClassMeta), but can be used if your swap has a template associated with it.- 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.
- template- The template string associated with this swap.
- Returns:
- The transformed object.
- Throws:
- Exception- If a problem occurred trying to convert the output.
 
- 
getNormalClassReturns the T class, the normalized form of the class.- Returns:
- The normal form of this class.
 
- 
getSwapClassReturns the G class, the generalized form of the class.Subclasses must override this method if the generalized class is Object, meaning it can produce multiple generalized forms.- Returns:
- The transformed form of this class.
 
- 
getSwapClassMetaReturns theClassMetaof the transformed class type.This value is cached for quick lookup. - Parameters:
- session- The bean context to use to get the class meta. This is always going to be the same bean context that created this swap.
- Returns:
- The ClassMetaof the transformed class type.
 
- 
isNormalObjectChecks if the specified object is an instance of the normal class defined on this swap.- Parameters:
- o- The object to check.
- Returns:
- true if the specified object is a subclass of the normal class defined on this transform.- null always return- false .
 
- 
isSwappedObjectChecks if the specified object is an instance of the swap class defined on this swap.- Parameters:
- o- The object to check.
- Returns:
- true if the specified object is a subclass of the transformed class defined on this transform.- null always return- false .
 
- 
toString
 
-