Class JdkTypeAdapterFactory

java.lang.Object
org.zkoss.zkmax.ui.JdkTypeAdapterFactory
All Implemented Interfaces:
com.google.gson.TypeAdapterFactory

public final class JdkTypeAdapterFactory extends Object implements com.google.gson.TypeAdapterFactory
A Gson TypeAdapterFactory for the value types of java.time and for TimeZone, whose fields Gson cannot access by reflection on Java 17 and later.

Available in ZK EE

A java.time value is written and read as the JSON object that Gson made of its fields by reflection on Java 11, such as {"year":2024,"month":1,"day":2} for a LocalDate; a field value that the type rejects, such as a month of 13, causes a JsonSyntaxException. A TimeZone of the JDK is written as the rawOffset and ID of that object only, since its other fields are internal to the JDK, and it is read by its ID with TimeZone.getTimeZone(String), so reading it as a SimpleTimeZone causes a JsonSyntaxException.

GsonConverter and GsonConverter register it. An application that specifies its own converter with the library property org.zkoss.zk.ui.jsonServiceParamConverter.class or org.zkoss.bind.jsonBindingParamConverter.class can register it with GsonBuilder.registerTypeAdapterFactory(com.google.gson.TypeAdapterFactory).

Since:
11.0.0
  • Constructor Details

    • JdkTypeAdapterFactory

      public JdkTypeAdapterFactory()
  • Method Details

    • create

      public <T> com.google.gson.TypeAdapter<T> create(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<T> type)
      Specified by:
      create in interface com.google.gson.TypeAdapterFactory