final class DefaultDateTypeAdapter extends java.lang.Object implements JsonSerializer<java.util.Date>, JsonDeserializer<java.util.Date>
| Modifier and Type | Field and Description |
|---|---|
private java.text.DateFormat |
enUsFormat |
private java.text.DateFormat |
iso8601Format |
private java.text.DateFormat |
localFormat |
| Constructor and Description |
|---|
DefaultDateTypeAdapter() |
DefaultDateTypeAdapter(java.text.DateFormat enUsFormat,
java.text.DateFormat localFormat) |
DefaultDateTypeAdapter(int style) |
DefaultDateTypeAdapter(int dateStyle,
int timeStyle) |
DefaultDateTypeAdapter(java.lang.String datePattern) |
| Modifier and Type | Method and Description |
|---|---|
java.util.Date |
deserialize(JsonElement json,
java.lang.reflect.Type typeOfT,
JsonDeserializationContext context)
Gson invokes this call-back method during deserialization when it encounters a field of the
specified type.
|
private java.util.Date |
deserializeToDate(JsonElement json) |
JsonElement |
serialize(java.util.Date src,
java.lang.reflect.Type typeOfSrc,
JsonSerializationContext context)
Gson invokes this call-back method during serialization when it encounters a field of the
specified type.
|
java.lang.String |
toString() |
private final java.text.DateFormat enUsFormat
private final java.text.DateFormat localFormat
private final java.text.DateFormat iso8601Format
DefaultDateTypeAdapter()
DefaultDateTypeAdapter(java.lang.String datePattern)
DefaultDateTypeAdapter(int style)
public DefaultDateTypeAdapter(int dateStyle,
int timeStyle)
DefaultDateTypeAdapter(java.text.DateFormat enUsFormat,
java.text.DateFormat localFormat)
public JsonElement serialize(java.util.Date src, java.lang.reflect.Type typeOfSrc, JsonSerializationContext context)
JsonSerializerIn the implementation of this call-back method, you should consider invoking
JsonSerializationContext.serialize(Object, Type) method to create JsonElements for any
non-trivial field of the src object. However, you should never invoke it on the
src object itself since that will cause an infinite loop (Gson will call your
call-back method again).
serialize in interface JsonSerializer<java.util.Date>src - the object that needs to be converted to Json.typeOfSrc - the actual type (fully genericized version) of the source object.public java.util.Date deserialize(JsonElement json, java.lang.reflect.Type typeOfT, JsonDeserializationContext context) throws JsonParseException
JsonDeserializerIn the implementation of this call-back method, you should consider invoking
JsonDeserializationContext.deserialize(JsonElement, Type) method to create objects
for any non-trivial field of the returned object. However, you should never invoke it on the
the same type passing json since that will cause an infinite loop (Gson will call your
call-back method again).
deserialize in interface JsonDeserializer<java.util.Date>json - The Json data being deserializedtypeOfT - The type of the Object to deserialize toTJsonParseException - if json is not in the expected format of typeofTprivate java.util.Date deserializeToDate(JsonElement json)
public java.lang.String toString()
toString in class java.lang.Object