Package org.one2team.highcharts.server

Source Code of org.one2team.highcharts.server.GsonHelper

package org.one2team.highcharts.server;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class GsonHelper {
 
  static String toJson (Object object) {
    return GSON.toJson(object);
  }
 
  private static Gson createGson () {
    GsonBuilder builder = new GsonBuilder();
    return builder
    .registerTypeAdapter (JSMDateTimeLabelFormats.class, new JSMDateTimeLabelFormatsSerializer ())
    .registerTypeAdapter (JSMStyle.class, new JSMStyleSerializer ())
    .setDateFormat(yyyy_MM_dd)
           .setExclusionStrategies (new ExclusionStrategy () {

            @Override
            public boolean shouldSkipClass (Class<?> arg0) {
              return false;
            }

            @Override
            public boolean shouldSkipField (FieldAttributes attributes) {
              return attributes.getName ().equals (USER_OBJECT);
            }
            
           }).create();
  }
 
  private static final String yyyy_MM_dd = "yyyyMMdd";
  private static final String USER_OBJECT = "userObject";

  private static final Gson GSON = createGson ();
}
TOP

Related Classes of org.one2team.highcharts.server.GsonHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.