Top Description Fields Constructors Methods
com.google.gson.internal.bind

pack-priv final Class JavaTimeTypeAdapters

extends Object
implements FactorySupplier
Class Inheritance
All Implemented Interfaces
com.google.gson.internal.bind.TypeAdapters.FactorySupplier
Annotations
@IgnoreJRERequirement
Static Imports
java.lang.Math.toIntExact

Type adapters for 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

Modifier and TypeField and Description
private static final TypeAdapter<Duration>
private static final TypeAdapter<Instant>
pack-priv static final TypeAdapterFactory
private static final TypeAdapter<LocalDate>
public 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

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public TypeAdapterFactory
private static TypeAdapter<LocalDateTime>
private static TypeAdapter<OffsetDateTime>
private static TypeAdapter<OffsetTime>
private static <T> T
requireNonNullField(T field, String fieldName, JsonReader reader)

private static TypeAdapter<ZonedDateTime>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DURATIONback to summary
private static final TypeAdapter<Duration> DURATION
INSTANTback to summary
private static final TypeAdapter<Instant> INSTANT
JAVA_TIME_FACTORYback to summary
pack-priv static final TypeAdapterFactory JAVA_TIME_FACTORY
LOCAL_DATEback to summary
private static final TypeAdapter<LocalDate> LOCAL_DATE
LOCAL_TIMEback to summary
public static final TypeAdapter<LocalTime> LOCAL_TIME
MONTH_DAYback to summary
private static final TypeAdapter<MonthDay> MONTH_DAY
PERIODback to summary
private static final TypeAdapter<Period> PERIOD
YEARback to summary
private static final TypeAdapter<Year> YEAR
YEAR_MONTHback to summary
private static final TypeAdapter<YearMonth> YEAR_MONTH
ZONE_IDback to summary
private static final TypeAdapter<ZoneId> ZONE_ID

Constructor Detail

JavaTimeTypeAdaptersback to summary
pack-priv JavaTimeTypeAdapters()

Method Detail

getback to summary
public TypeAdapterFactory get()

Implements com.google.gson.internal.bind.TypeAdapters.FactorySupplier.get.

Annotations
@Override
localDateTimeback to summary
private static TypeAdapter<LocalDateTime> localDateTime(Gson gson)
offsetDateTimeback to summary
private static TypeAdapter<OffsetDateTime> offsetDateTime(Gson gson)
offsetTimeback to summary
private static TypeAdapter<OffsetTime> offsetTime(Gson gson)
requireNonNullFieldback to summary
private static <T> T requireNonNullField(T field, String fieldName, JsonReader reader)
zonedDateTimeback to summary
private static TypeAdapter<ZonedDateTime> zonedDateTime(Gson gson)