Package org.apache.juneau.swaps
Class TemporalSwap
- Direct Known Subclasses:
TemporalSwap.BasicIsoDate,TemporalSwap.IsoDate,TemporalSwap.IsoDateTime,TemporalSwap.IsoInstant,TemporalSwap.IsoLocalDate,TemporalSwap.IsoLocalDateTime,TemporalSwap.IsoLocalTime,TemporalSwap.IsoOffsetDate,TemporalSwap.IsoOffsetDateTime,TemporalSwap.IsoOffsetTime,TemporalSwap.IsoOrdinalDate,TemporalSwap.IsoTime,TemporalSwap.IsoWeekDate,TemporalSwap.IsoYear,TemporalSwap.IsoYearMonth,TemporalSwap.IsoZonedDateTime,TemporalSwap.Rfc1123DateTime
Swap that converts
Temporal objects to strings.
Uses the DateTimeFormatter class for converting Temporal objects to and from strings.
Supports any of the following temporal objects:
HijrahDateInstantJapaneseDateLocalDateLocalDateTimeLocalTimeMinguoDateOffsetDateTimeOffsetTimeThaiBuddhistDateYearYearMonthZonedDateTime
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefault swap toDateTimeFormatter.BASIC_ISO_DATE.static classDefault swap toDateTimeFormatter.ISO_DATE.static classDefault swap toDateTimeFormatter.ISO_DATE_TIME.static classDefault swap toDateTimeFormatter.ISO_INSTANT.static classDefault swap toDateTimeFormatter.ISO_LOCAL_DATE.static classDefault swap toDateTimeFormatter.ISO_LOCAL_DATE_TIME.static classDefault swap toDateTimeFormatter.ISO_LOCAL_TIME.static classDefault swap toDateTimeFormatter.ISO_OFFSET_DATE.static classDefault swap toDateTimeFormatter.ISO_OFFSET_DATE_TIME.static classDefault swap toDateTimeFormatter.ISO_OFFSET_TIME.static classDefault swap toDateTimeFormatter.ISO_ORDINAL_DATE.static classDefault swap toDateTimeFormatter.ISO_TIME.static classDefault swap toDateTimeFormatter.ISO_WEEK_DATE.static classDefault swap toDateTimeFormatter.ISO_WEEK_DATE.static classDefault swap toDateTimeFormatter.ISO_WEEK_DATE.static classDefault swap toDateTimeFormatter.ISO_ZONED_DATE_TIME.static classDefault swap toDateTimeFormatter.RFC_1123_DATE_TIME. -
Field Summary
Fields inherited from class org.apache.juneau.swap.ObjectSwap
NULL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TemporalconvertToSerializable(BeanSession session, Temporal t) Converts the specified temporal object to a form suitable to be serialized using any pattern.swap(BeanSession session, Temporal o) If this transform is to be used to serialize non-serializable objects, it must implement this method.unswap(BeanSession session, String f, ClassMeta<?> hint) If this transform is to be used to reconstitute objects that aren't true Java beans, it must implement this method.protected booleanReturnstrue if the time zone on the pattern is optional.Methods inherited from class org.apache.juneau.swap.ObjectSwap
forMediaTypes, forMediaTypes, getNormalClass, getSwapClass, getSwapClassMeta, isNormalObject, isSwappedObject, match, swap, toString, unswap, withTemplate, withTemplate
-
Constructor Details
-
TemporalSwap
Constructor.- Parameters:
pattern- The timestamp format or name of predefinedDateTimeFormatter.zoneOptional-true if the time zone on the pattern is optional.
-
-
Method Details
-
swap
Description copied from class:ObjectSwapIf 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.
- Overrides:
swapin classStringSwap<Temporal>- 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.
-
-
unswap
Description copied from class:ObjectSwapIf this transform is to be used to reconstitute objects that aren't true Java beans, it must implement this method.- Overrides:
unswapin classStringSwap<Temporal>- 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 typeGregorianCalendar.
This may benull if the parser cannot make this determination.- Returns:
- The narrowed object.
- Throws:
Exception- If this method is not implemented.
-
convertToSerializable
Converts the specified temporal object to a form suitable to be serialized using any pattern.- Parameters:
session- The current bean session.t- The temporal object to convert.- Returns:
- The converted temporal object.
-
zoneOptional
Returnstrue if the time zone on the pattern is optional.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.
- Returns:
true if the time zone on the pattern is optional.
-