Java Code Examples for com.google.gson.GsonBuilder#serializeSpecialFloatingPointValues()
The following examples show how to use
com.google.gson.GsonBuilder#serializeSpecialFloatingPointValues() .
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: UtilFns.java From SmoothNLP with GNU General Public License v3.0 | 5 votes |
public static String toJson(Object o){ GsonBuilder gb = new GsonBuilder(); gb = gb.serializeSpecialFloatingPointValues(); gb = gb.serializeNulls(); Gson gson = gb.create(); return gson.toJson(o); }
Example 2
Source File: ProximityForestResult.java From ProximityForest with GNU General Public License v3.0 | 5 votes |
public String exportJSON(String datasetName, int experiment_id) throws Exception { String file = ""; String timestamp = LocalDateTime.now() .format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss_SSS")); file = AppContext.output_dir + File.separator + forest_id + timestamp; File fileObj = new File(file); fileObj.getParentFile().mkdirs(); fileObj.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))){ Gson gson; GsonBuilder gb = new GsonBuilder(); gb.serializeSpecialFloatingPointValues(); gb.serializeNulls(); gson = gb.create(); // SerializableResultSet object = new SerializableResultSet(this.forests); bw.write(gson.toJson(this)); bw.close(); } catch (IOException e) { e.printStackTrace(); }finally { // bw.close(); } return file; }
Example 3
Source File: EventSerializerGson.java From JEEventStore with MIT License | 5 votes |
/** * Create the underlying GsonBuilder. * 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; }
Example 4
Source File: GsonHelper.java From sumk with Apache License 2.0 | 4 votes |
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; }
Example 5
Source File: Weather.java From BackPackTrackII with GNU General Public License v3.0 | 4 votes |
public String serialize() { GsonBuilder builder = new GsonBuilder(); builder.serializeSpecialFloatingPointValues(); Gson gson = builder.create(); return gson.toJson(this); }
Example 6
Source File: Weather.java From BackPackTrackII with GNU General Public License v3.0 | 4 votes |
public static Weather deserialize(String text) { GsonBuilder builder = new GsonBuilder(); builder.serializeSpecialFloatingPointValues(); Gson gson = builder.create(); return gson.fromJson(text, Weather.class); }