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

public final Class DefaultDateTypeAdapter<T extends Date>

extends TypeAdapter<T extends Date>
Class Inheritance
Imports
com.google.gson.Gson, .JsonSyntaxException, .TypeAdapter, .TypeAdapterFactory, com.google.gson.internal.JavaVersion, .PreJava9DateFormatProvider, com.google.gson.internal.bind.util.ISO8601Utils, com.google.gson.reflect.TypeToken, com.google.gson.stream.JsonReader, .JsonToken, .JsonWriter, java.io.IOException, java.text.DateFormat, .ParseException, .ParsePosition, .SimpleDateFormat, java.util.ArrayList, .Date, .List, .Locale, .Objects, .TimeZone

This type adapter supports subclasses of date by defining a DefaultDateTypeAdapter.DateType and then using its createAdapterFactory methods.

Important Note

Instances of this class (or rather the SimpleDateFormat they use) capture the current default Locale and TimeZone when they are created. Therefore avoid storing factories obtained from DateType in static fields, since they only create a single adapter instance and its behavior would then depend on when Gson classes are loaded first, and which default Locale and TimeZone was used at that point.

Authors
Inderjeet Singh, Joel Leitch

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class

Field Summary

Modifier and TypeField and Description
private final List<DateFormat>
dateFormats

List of 1 or more different date formats used for de-serialization attempts.

private final DefaultDateTypeAdapter.DateType<T>
public static final TypeAdapterFactory
DEFAULT_STYLE_FACTORY

Factory for Date adapters which use DateFormat#DEFAULT as style.

private static final String

Constructor Summary

AccessConstructor and Description
private
private
DefaultDateTypeAdapter(DefaultDateTypeAdapter.DateType<T> dateType, int dateStyle, int timeStyle)

Method Summary

Modifier and TypeMethod and Description
private Date
public T
read(JsonReader in)

Implements abstract com.google.gson.TypeAdapter.read.

Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
write(JsonWriter out, Date value)

Implements abstract com.google.gson.TypeAdapter.write.

Writes one JSON value (an array, object, string, number, boolean or null) for value.

Inherited from com.google.gson.TypeAdapter:
fromJsonfromJsonfromJsonTreenullSafetoJsontoJsontoJsonTree

Field Detail

dateFormatsback to summary
private final List<DateFormat> dateFormats

List of 1 or more different date formats used for de-serialization attempts. The first of them is used for serialization as well.

dateTypeback to summary
private final DefaultDateTypeAdapter.DateType<T> dateType
DEFAULT_STYLE_FACTORYback to summary
public static final TypeAdapterFactory DEFAULT_STYLE_FACTORY

Factory for Date adapters which use DateFormat#DEFAULT as style.

SIMPLE_NAMEback to summary
private static final String SIMPLE_NAME

Constructor Detail

DefaultDateTypeAdapterback to summary
private DefaultDateTypeAdapter(DefaultDateTypeAdapter.DateType<T> dateType, String datePattern)
DefaultDateTypeAdapterback to summary
private DefaultDateTypeAdapter(DefaultDateTypeAdapter.DateType<T> dateType, int dateStyle, int timeStyle)

Method Detail

deserializeToDateback to summary
private Date deserializeToDate(JsonReader in) throws IOException
readback to summary
public T read(JsonReader in) throws IOException

Implements abstract com.google.gson.TypeAdapter.read.

Doc from com.google.gson.TypeAdapter.read.

Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object. Returns the converted object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
writeback to summary
public void write(JsonWriter out, Date value) throws IOException

Implements abstract com.google.gson.TypeAdapter.write.

Doc from com.google.gson.TypeAdapter.write.

Writes one JSON value (an array, object, string, number, boolean or null) for value.

Annotations
@Override
com.google.gson.internal.bind back to summary

public abstract Class DefaultDateTypeAdapter.DateType<T extends Date>

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.gson.internal.bind.DefaultDateTypeAdapter.DateType

Field Summary

Modifier and TypeField and Description
public static final DefaultDateTypeAdapter.DateType<Date>
private final Class<T>

Constructor Summary

AccessConstructor and Description
protected
DateType(Class<T> dateClass)

Method Summary

Modifier and TypeMethod and Description
public final TypeAdapterFactory
public final TypeAdapterFactory
createAdapterFactory(int dateStyle, int timeStyle)

private TypeAdapterFactory
protected abstract T
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DATEback to summary
public static final DefaultDateTypeAdapter.DateType<Date> DATE
dateClassback to summary
private final Class<T> dateClass

Constructor Detail

DateTypeback to summary
protected DateType(Class<T> dateClass)

Method Detail

createAdapterFactoryback to summary
public final TypeAdapterFactory createAdapterFactory(String datePattern)
createAdapterFactoryback to summary
public final TypeAdapterFactory createAdapterFactory(int dateStyle, int timeStyle)
createFactoryback to summary
private TypeAdapterFactory createFactory(DefaultDateTypeAdapter<T> adapter)
deserializeback to summary
protected abstract T deserialize(Date date)