List of usage examples for com.google.gson GsonBuilder serializeSpecialFloatingPointValues
boolean serializeSpecialFloatingPointValues
To view the source code for com.google.gson GsonBuilder serializeSpecialFloatingPointValues.
Click Source Link
From source file:com.bitalino.server.rest.json.GsonProvider.java
License:Apache License
/** * Hereby one will register every subtypes to be supported by Gson. *//*from www . j av a 2s . c om*/ private static final Gson registerGsonTypeAdapterFactories() { GsonBuilder builder = new GsonBuilder(); // handle double NaN builder.serializeSpecialFloatingPointValues(); // register // builder.registerTypeAdapterFactory(RuntimeTypeAdapterFactory // .of(Result.class).registerSubtype(LatencyResult.class) // .registerSubtype(DownloadUploadResult.class) // .registerSubtype(WebPageAccessResult.class)); return builder.create(); }
From source file:com.cloudbees.eclipse.core.util.Utils.java
License:Open Source License
public static Gson createGson() { final GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.serializeSpecialFloatingPointValues(); gsonBuilder.serializeNulls();//from w w w .j ava2 s . co m // gsonBuilder.setPrettyPrinting(); // temporary // gsonBuilder.excludeFieldsWithoutExposeAnnotation(); Gson g = gsonBuilder.create(); return g; }
From source file:com.fiftycuatro.providers.GsonProvider.java
License:Apache License
/** * Hereby one will register every subtypes to be supported by Gson. *//*from w ww . j a v a 2 s .c o m*/ private static final Gson registerGsonTypeAdapterFactories() { GsonBuilder builder = new GsonBuilder(); // handle double NaN builder.serializeSpecialFloatingPointValues(); // register subtypes // builder.registerTypeAdapterFactory(RuntimeTypeAdapterFactory // .of(Object.class).registerSubtype(SubObjecOne.class) // .registerSubtype(SubObjecTwo.class) // .registerSubtype(SubObjecThree.class)); return builder.create(); }
From source file:org.jeeventstore.serialization.gson.EventSerializerGson.java
License:Open Source License
/** * Create the underlying GsonBuilder./*from www . ja va 2s.co m*/ * Added here to test proper serialization in integration tests. */ public static GsonBuilder createBuilder() { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(EventList.class, new EventListTypeConverter()); builder.serializeSpecialFloatingPointValues(); // required to serialize Double.POSITIVE_INFINITY and others builder.enableComplexMapKeySerialization(); // required to properly serialize maps builder.setDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); // granularity of 1 ms return builder; }
From source file:org.structr.rest.servlet.ThreadLocalGson.java
License:Open Source License
@Override protected Gson initialValue() { ResultGSONAdapter resultGsonAdapter = new ResultGSONAdapter(propertyView, outputNestingDepth); JsonInputGSONAdapter jsonInputAdapter = new JsonInputGSONAdapter(); // create GSON serializer final GsonBuilder gsonBuilder = new GsonBuilder().setPrettyPrinting().serializeNulls() .registerTypeHierarchyAdapter(FrameworkException.class, new FrameworkExceptionGSONAdapter()) .registerTypeAdapter(IJsonInput.class, jsonInputAdapter) .registerTypeAdapter(Result.class, resultGsonAdapter); final boolean lenient = Boolean.parseBoolean(StructrApp.getConfigurationValue("json.lenient", "false")); if (lenient) { // Serializes NaN, -Infinity, Infinity, see http://code.google.com/p/google-gson/issues/detail?id=378 gsonBuilder.serializeSpecialFloatingPointValues(); }//from w ww . j a v a2 s . c o m return gsonBuilder.create(); }
From source file:us.blanshard.sudoku.messages.Rpc.java
License:Apache License
/** * Registers type adapters in the given builder so that {@link Request} and * {@link Response} objects can be serialized and deserialized in a symmetric * way.// w ww. j av a2 s .c o m * * <p> * The request deserializer requires the "method" field of the request to come * before the "params" field, which requirement is not strictly conformant * with JSON. The serializer ensures that they are in that order. * * <p> * Likewise, the response's "id" field must come before the "result" field. */ public static GsonBuilder register(GsonBuilder builder, final Function<String, Type> methodToParamsType, final Function<Integer, Type> idToResultType) { builder.registerTypeAdapterFactory(new TypeAdapterFactory() { @SuppressWarnings("unchecked") @Override public <T> TypeAdapter<T> create(final Gson gson, TypeToken<T> type) { if (type.getRawType() == Request.class) { TypeAdapter<Request> typeAdapter = new RequestAdapter(gson, methodToParamsType); return (TypeAdapter<T>) typeAdapter.nullSafe(); } if (type.getRawType() == Response.class) { TypeAdapter<Response<Object>> typeAdapter = new ResponseAdapter(gson, idToResultType); return (TypeAdapter<T>) typeAdapter.nullSafe(); } return null; } }); return builder.serializeSpecialFloatingPointValues(); }