Code example for GsonBuilder

Methods: createregisterTypeAdaptersetPrettyPrinting

0
 
   private Gson gson = null;
 
   @Before 
   public void init() { 
      GsonBuilder gsonBuilder = new GsonBuilder();
      gsonBuilder.setPrettyPrinting(); // only for debug/development
      gsonBuilder.registerTypeAdapter(Category.class, new CategorySerializer());
      gsonBuilder.registerTypeAdapter(Category.class, new CategoryDeserializer());
      gsonBuilder.registerTypeAdapter(Tool.class, new ToolSerializer());
      gsonBuilder.registerTypeAdapter(Tool.class, new ToolDeserializer());
      gsonBuilder.registerTypeAdapter(Feature.class, new FeatureSerializer());
      gsonBuilder.registerTypeAdapter(Feature.class, new FeatureDeserializer());
 
//      gsonBuilder.registerTypeAdapter(QueryAllArticles.class, new QueryAllArticlesDeserializer()); 
//      gsonBuilder.registerTypeAdapter(QueryChannel.class, new QueryChannelDeserializer()); 
//      gsonBuilder.registerTypeAdapter(QuerySource.class, new QuerySourceDeserializer()); 
 
      gson = gsonBuilder.create();
   } 
 
 
   @Test 
   public void categorySerializerTest() throws ParseException {