Class JavaTimeTypeAdapters
- All Implemented Interfaces:
TypeAdapters.FactorySupplier
java.time types.
These adapters mimic what ReflectiveTypeAdapterFactory would produce for the same
types. That is by no means a natural encoding, given that many of the types have standard ISO
representations. If Gson had added support for the types at the same time they appeared (in Java
8, released in 2014), it would surely have used those representations. Unfortunately, in the
intervening time, people have been using the reflective representations, and changing that would
potentially be incompatible. Meanwhile, depending on the details of private fields in JDK classes
is obviously fragile, and it also needs special --add-opens configuration with more
recent JDK versions. So here we freeze the representation that was current with JDK 21, in a way
that does not use reflection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final TypeAdapter<Duration>private static final TypeAdapter<Instant>(package private) static final TypeAdapterFactoryprivate static final TypeAdapter<LocalDate>static final TypeAdapter<LocalTime>private static final TypeAdapter<MonthDay>private static final TypeAdapter<Period>private static final TypeAdapter<Year>private static final TypeAdapter<YearMonth>private static final TypeAdapter<ZoneId> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget()private static TypeAdapter<LocalDateTime>localDateTime(Gson gson) private static TypeAdapter<OffsetDateTime>offsetDateTime(Gson gson) private static TypeAdapter<OffsetTime>offsetTime(Gson gson) private static <T> TrequireNonNullField(T field, String fieldName, JsonReader reader) private static TypeAdapter<ZonedDateTime>zonedDateTime(Gson gson)
-
Field Details
-
DURATION
-
INSTANT
-
LOCAL_DATE
-
LOCAL_TIME
-
MONTH_DAY
-
PERIOD
-
YEAR
-
YEAR_MONTH
-
ZONE_ID
-
JAVA_TIME_FACTORY
-
-
Constructor Details
-
JavaTimeTypeAdapters
JavaTimeTypeAdapters()
-
-
Method Details
-
get
- Specified by:
getin interfaceTypeAdapters.FactorySupplier
-
localDateTime
-
offsetDateTime
-
offsetTime
-
zonedDateTime
-
requireNonNullField
-