MCPcopy Create free account
hub / github.com/ddf-project/DDF / serialize

Method serialize

core/src/main/java/io/ddf/util/Utils.java:344–362  ·  view source on GitHub ↗
(Object obj)

Source from the content-addressed store, hash-verified

342
343
344 public static String serialize(Object obj) throws DDFException {
345 if (obj == null) return "null";
346
347 if (obj instanceof ISerializable) ((ISerializable) obj).beforeSerialization();
348
349 Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
350 String json = gson.toJson(obj);
351
352 // Add the bookkeeping fields, e.g., SERDES_CLASS_NAME_FIELD
353 JsonObject jObj = toJsonObject(json);
354 jObj.addProperty(SERDES_CLASS_NAME_FIELD, obj.getClass().getName());
355 jObj.addProperty(SERDES_TIMESTAMP_FIELD, DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG)
356 .format(new Date()));
357 jObj.addProperty(SERDES_USER_FIELD, System.getProperty("user.name"));
358
359
360 json = gson.toJson(jObj);
361 return json;
362 }
363
364 private static JsonObject toJsonObject(String json) {
365 JsonElement jElement = new JsonParser().parse(json);

Callers 1

persistMethod · 0.95

Calls 4

toJsonObjectMethod · 0.95
beforeSerializationMethod · 0.65
toJsonMethod · 0.65
getNameMethod · 0.65

Tested by

no test coverage detected