public static Map<String, Object> asMap(JsonObject jsonObject) { if (jsonObject != null) { Map<String, Object> map = null; try { map = getGsonMapper().fromJson(jsonObject, MAP_TYPE_TOKEN); } catch (JsonParseException | ClassCastException e) { LOG.logJsonException(e); } if (map != null) { for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); if (value != null && value instanceof JsonPrimitive) { Object rawObject = asPrimitiveObject((JsonPrimitive) value); if (rawObject != null) { map.put(entry.getKey(), rawObject); } } } return map; } else { return Collections.emptyMap(); } } else { return Collections.emptyMap(); } }
public static Map<String, Object> asMap(JsonObject jsonObject) { if (jsonObject != null) { Map<String, Object> map = null; try { map = getGsonMapper().fromJson(jsonObject, MAP_TYPE_TOKEN); } catch (JsonParseException | ClassCastException e) { LOG.logJsonException(e); } if (map != null) { for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); if (value != null && value instanceof JsonPrimitive) { Object rawObject = asPrimitiveObject((JsonPrimitive) value); if (rawObject != null) { map.put(entry.getKey(), rawObject); } } } return map; } else { return Collections.emptyMap(); } } else { return Collections.emptyMap(); } }
public Map<String, Object> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { Map<String, Object> map = new HashMap<>(); for (Map.Entry<String, JsonElement> entry : getObject(json).entrySet()) { if (entry != null) { String key = entry.getKey(); JsonElement jsonElement = entry.getValue(); if (jsonElement != null && jsonElement.isJsonNull()) { map.put(key, null); } else if (jsonElement != null && jsonElement.isJsonPrimitive()) { Object rawValue = asPrimitiveObject((JsonPrimitive) jsonElement); if (rawValue != null) { map.put(key, rawValue); } } } } return map; } })
public Map<String, Object> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { Map<String, Object> map = new HashMap<>(); for (Map.Entry<String, JsonElement> entry : getObject(json).entrySet()) { if (entry != null) { String key = entry.getKey(); JsonElement jsonElement = entry.getValue(); if (jsonElement != null && jsonElement.isJsonNull()) { map.put(key, null); } else if (jsonElement != null && jsonElement.isJsonPrimitive()) { Object rawValue = asPrimitiveObject((JsonPrimitive) jsonElement); if (rawValue != null) { map.put(key, rawValue); } } } } return map; } })
public static Object getRawObject(JsonObject jsonObject, String memberName) { if (jsonObject == null || memberName == null) { return null; } Object rawValue = null; if (jsonObject.has(memberName)) { JsonPrimitive jsonPrimitive = null; try { jsonPrimitive = jsonObject.getAsJsonPrimitive(memberName); } catch (ClassCastException e) { LOG.logJsonException(e); } if (jsonPrimitive != null) { rawValue = asPrimitiveObject(jsonPrimitive); } } if (rawValue != null) { return rawValue; } else { return null; } }
public static Object getRawObject(JsonObject jsonObject, String memberName) { if (jsonObject == null || memberName == null) { return null; } Object rawValue = null; if (jsonObject.has(memberName)) { JsonPrimitive jsonPrimitive = null; try { jsonPrimitive = jsonObject.getAsJsonPrimitive(memberName); } catch (ClassCastException e) { LOG.logJsonException(e); } if (jsonPrimitive != null) { rawValue = asPrimitiveObject(jsonPrimitive); } } if (rawValue != null) { return rawValue; } else { return null; } }