Class DateTimeConverter
- java.lang.Object
-
- com.github.mavolin.maxon.converter.DateTimeConverter
-
- All Implemented Interfaces:
JsonConverter
public class DateTimeConverter extends Object implements JsonConverter
TheDateTimeConverter
is used for converting the various date and time representing objects of Java 8'sjava.time
package, namelyLocalTime
,LocalDate
,LocalDateTime
,OffsetDateTime
andZonedDateTime
, as well asDate
.
-
-
Constructor Summary
Constructors Constructor Description DateTimeConverter(DateFormatConfiguration dateFormatConfiguration)
Instantiates a newDateTimeConverter
, that uses the passedDateFormatConfiguration
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonValue
getAsJson(Object source)
Converts the givenObject
to its JSON representation.<T> T
getFromJson(JsonValue source, Class<T> clazz)
Parses the passedJsonValue
and returns an object of the typeT
.
-
-
-
Constructor Detail
-
DateTimeConverter
public DateTimeConverter(DateFormatConfiguration dateFormatConfiguration)
Instantiates a newDateTimeConverter
, that uses the passedDateFormatConfiguration
- Parameters:
dateFormatConfiguration
- the dateDateFormatConfiguration
-
-
Method Detail
-
getAsJson
public JsonValue getAsJson(Object source)
Converts the givenObject
to its JSON representation.- Specified by:
getAsJson
in interfaceJsonConverter
- Parameters:
source
- theObject
that is to be converted- Returns:
- the JSON representation
-
getFromJson
public <T> T getFromJson(JsonValue source, Class<T> clazz)
Parses the passedJsonValue
and returns an object of the typeT
. The JSON must be a String holding the date/time'sString
representation.- Specified by:
getFromJson
in interfaceJsonConverter
- Type Parameters:
T
- the type parameter- Parameters:
source
- theJsonValue
clazz
- theClass
- Returns:
- the extracted
Object
of the typeT
.
-
-