Java Code Examples for com.google.gson.GsonBuilder#setLongSerializationPolicy()

The following examples show how to use com.google.gson.GsonBuilder#setLongSerializationPolicy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChannelModelProvider.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
static Gson createGson ()
{
    final GsonBuilder builder = new GsonBuilder ();

    builder.setPrettyPrinting ();
    builder.setLongSerializationPolicy ( LongSerializationPolicy.STRING );
    builder.setDateFormat ( DATE_FORMAT );
    builder.registerTypeAdapter ( MetaKey.class, new JsonDeserializer<MetaKey> () {

        @Override
        public MetaKey deserialize ( final JsonElement json, final Type type, final JsonDeserializationContext ctx ) throws JsonParseException
        {
            return MetaKey.fromString ( json.getAsString () );
        }
    } );

    return builder.create ();
}
 
Example 2
Source File: GSONUtil.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
GSONUtil() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setLongSerializationPolicy(LongSerializationPolicy.STRING);
    // gsonBuilder.setPrettyPrinting();

    gson = gsonBuilder.create();
}
 
Example 3
Source File: HttpGson.java    From sumk with Apache License 2.0 5 votes vote down vote up
private static GsonBuilder gsonBuilder() {
	GsonBuilder gb = GsonHelper.builder("sumk.http");

	if (AppInfo.getBoolean("sumk.http.json.long2String", true)) {
		gb.setLongSerializationPolicy(LongSerializationPolicy.STRING);
	}
	return gb;
}
 
Example 4
Source File: GsonHelper.java    From sumk with Apache License 2.0 4 votes vote down vote up
public static GsonBuilder builder(String module) {
	if (module == null || module.isEmpty()) {
		module = "sumk";
	}

	DateTimeTypeAdapter da = new DateTimeTypeAdapter();
	String format = AppInfo.get(module + ".gson.date.format");
	if (StringUtil.isNotEmpty(format)) {
		da.setDateFormat(format);
	}

	GsonBuilder gb = new GsonBuilder().registerTypeAdapter(Date.class, da);

	if (AppInfo.getBoolean(module + ".gson.disableHtmlEscaping", false)) {
		gb.disableHtmlEscaping();
	}
	if (AppInfo.getBoolean(module + ".gson.shownull", false)) {
		gb.serializeNulls();
	}
	if (AppInfo.getBoolean(module + ".gson.disableInnerClassSerialization", false)) {
		gb.disableInnerClassSerialization();
	}
	if (AppInfo.getBoolean(module + ".gson.generateNonExecutableJson", false)) {
		gb.generateNonExecutableJson();
	}
	if (AppInfo.getBoolean(module + ".gson.serializeSpecialFloatingPointValues", false)) {
		gb.serializeSpecialFloatingPointValues();
	}

	if (AppInfo.getBoolean(module + ".gson.longSerialize2String", false)) {
		gb.setLongSerializationPolicy(LongSerializationPolicy.STRING);
	}

	if (AppInfo.getBoolean(module + ".gson.prettyPrinting", false)) {
		gb.setPrettyPrinting();
	}
	if (AppInfo.getBoolean(module + ".gson.date.adaper", true)) {
		DateAdapters.registerAll(gb);
	}
	return gb;
}