public class TemporalSwap extends StringSwap<Temporal>
Temporal
objects to strings.
Uses the DateTimeFormatter
class for converting Temporal
objects to and from strings.
Supports any of the following temporal objects:
Constructor and Description |
---|
TemporalSwap(String pattern,
boolean zoneOptional)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected Temporal |
convertToSerializable(BeanSession session,
Temporal t)
Converts the specified temporal object to a form suitable to be serialized using any pattern.
|
String |
swap(BeanSession session,
Temporal o)
If this transform is to be used to serialize non-serializable POJOs, it must implement this method.
|
Temporal |
unswap(BeanSession session,
String f,
ClassMeta<?> hint)
If this transform is to be used to reconstitute POJOs that aren't true Java beans, it must implement this method.
|
protected boolean |
zoneOptional()
Returns
|
forMediaTypes, forMediaTypes, getNormalClass, getSwapClass, getSwapClassMeta, isNormalObject, isSwappedObject, match, swap, toString, unswap, withTemplate, withTemplate
public TemporalSwap(String pattern, boolean zoneOptional)
pattern
- The timestamp format or name of predefined DateTimeFormatter
.zoneOptional
- protected boolean zoneOptional()
If it's not optional, then local dates/times must be converted into zoned times using the session time zone. Otherwise, local date/times are fine.
public String swap(BeanSession session, Temporal o) throws Exception
PojoSwap
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.
swap
in class StringSwap<Temporal>
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.Exception
- If a problem occurred trying to convert the output.protected Temporal convertToSerializable(BeanSession session, Temporal t)
session
- The current bean session.t
- The temporal object to convert.public Temporal unswap(BeanSession session, String f, ClassMeta<?> hint) throws Exception
PojoSwap
unswap
in class StringSwap<Temporal>
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
.
Exception
- If this method is not implemented.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.