(Object obj)
| 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); |
no test coverage detected