Class GsonSerializerDeserializerForIBeans

  • All Implemented Interfaces:
    JsonDeserializer<GsonSupport>, JsonSerializer<GsonSupport>

    public class GsonSerializerDeserializerForIBeans
    extends Object
    implements JsonSerializer<GsonSupport>, JsonDeserializer<GsonSupport>
    JSON serializer/deserializer used with Gson to convert IBeans with extension interface GsonSupport from and to JSON. Three prerequisites need to be fulfilled so that an IBean can be converted to and from JSON with Gson:

    Following code snippets show an example usage:

     
        IBeanFactory factory = null;
    
        // Create a Gson JSON converter with IBean serializer/deserializer configured
        final Gson gson = new GsonBuilder().registerTypeHierarchyAdapter(GsonSupport.class,
                new GsonSerializerDeserializerForIBeans(factory)).create();
        
        // BeanType must extend interface GsonSupport
        BeanType someBean = factory.create(BeanType.class);
        
        // Serialize and deserialize IBean
        String json = gson.toJson(someBean);
        BeanType deserializedBean = gson.fromJson(json, BeanType.class);