List of usage examples for com.google.gson JsonElement isJsonNull
public boolean isJsonNull()
From source file:org.sourcepit.consul.forwarder.GsonUtils.java
License:Apache License
public static JsonArray getAsJsonArray(final JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return new JsonArray(); }/*from w ww .ja v a 2 s . co m*/ return jsonElement.getAsJsonArray(); }
From source file:org.sourcepit.consul.forwarder.GsonUtils.java
License:Apache License
public static JsonObject getAsJsonObject(final JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return null; }/* www . ja v a 2s. co m*/ return jsonElement.getAsJsonObject(); }
From source file:org.sourcepit.consul.forwarder.GsonUtils.java
License:Apache License
public static String getAsString(JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return null; }//from w w w . j av a2s .co m return jsonElement.getAsString(); }
From source file:org.sourcepit.consul.forwarder.GsonUtils.java
License:Apache License
public static Integer getAsInteger(JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return null; }//ww w. j ava2 s . c o m return Integer.valueOf(jsonElement.getAsInt()); }
From source file:org.sourcepit.docker.watcher.ConsulForwarder.java
License:Apache License
private JsonArray getAsJsonArray(JsonObject object, String member) { final JsonElement jsonElement = object.get(member); if (jsonElement == null || jsonElement.isJsonNull()) { return new JsonArray(); }/* ww w . j a va 2 s.com*/ return jsonElement.getAsJsonArray(); }
From source file:org.sourcepit.docker.watcher.ConsulForwarder.java
License:Apache License
private JsonObject getAsJsonObject(final JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return null; }/*w w w. ja v a 2 s .co m*/ return jsonElement.getAsJsonObject(); }
From source file:org.sourcepit.docker.watcher.ConsulForwarder.java
License:Apache License
private String getAsString(JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return null; }// w w w.j av a 2s .c o m return jsonElement.getAsString(); }
From source file:org.sourcepit.docker.watcher.ConsulForwarder.java
License:Apache License
private Integer getAsInteger(JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return null; }//from w ww.ja va 2 s. co m return Integer.valueOf(jsonElement.getAsInt()); }
From source file:org.structr.core.JsonInputGSONAdapter.java
License:Open Source License
@Override public JsonInput deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonInput wrapper = new JsonInput(); if (json.isJsonObject()) { JsonObject obj = json.getAsJsonObject(); for (Entry<String, JsonElement> entry : obj.entrySet()) { String key = entry.getKey(); JsonElement elem = entry.getValue(); // static mapping of IdProperty if present if ((idProperty != null) && "id".equals(key)) { key = idProperty.jsonName(); }/*from w w w . j a v a 2 s .c om*/ if (elem.isJsonNull()) { wrapper.add(key, null); } else if (elem.isJsonObject()) { wrapper.add(key, deserialize(elem, typeOfT, context)); } else if (elem.isJsonArray()) { JsonArray array = elem.getAsJsonArray(); List list = new LinkedList(); for (JsonElement element : array) { if (element.isJsonPrimitive()) { list.add(fromPrimitive((element.getAsJsonPrimitive()))); } else if (element.isJsonObject()) { // create map of values list.add(deserialize(element, typeOfT, context)); } } wrapper.add(key, list); } else if (elem.isJsonPrimitive()) { // wrapper.add(key, elem.getAsString()); wrapper.add(key, fromPrimitive((JsonPrimitive) elem)); } } } else if (json.isJsonArray()) { JsonArray array = json.getAsJsonArray(); for (JsonElement elem : array) { if (elem.isJsonPrimitive()) { wrapper.add(elem.toString(), ((JsonPrimitive) elem).getAsString()); } else if (elem.isJsonObject()) { wrapper.add(elem.toString(), deserialize(elem, typeOfT, context)); } else if (elem.isJsonArray()) { wrapper.add(elem.toString(), deserialize(elem, typeOfT, context)); } } } return wrapper; }
From source file:org.structr.core.PropertySetGSONAdapter.java
License:Open Source License
private PropertySet deserializeFlatNameValue(JsonElement json, Type typeOfT, JsonDeserializationContext context) { PropertySet wrapper = new PropertySet(); if (json.isJsonObject()) { JsonObject obj = json.getAsJsonObject(); for (Entry<String, JsonElement> entry : obj.entrySet()) { String key = entry.getKey(); JsonElement elem = entry.getValue(); // static mapping of IdProperty if present if ((idProperty != null) && "id".equals(key)) { key = idProperty;//from w w w . ja v a 2 s . c o m } if (elem.isJsonNull()) { wrapper.add(key, null); } else if (elem.isJsonObject()) { wrapper.add(key, deserializeFlatNameValue(elem, typeOfT, context)); } else if (elem.isJsonArray()) { JsonArray array = elem.getAsJsonArray(); List list = new LinkedList(); for (JsonElement element : array) { if (element.isJsonPrimitive()) { list.add(fromPrimitive((element.getAsJsonPrimitive()))); } else if (element.isJsonObject()) { // create map of values list.add(deserializeFlatNameValue(element, typeOfT, context)); } } wrapper.add(key, list); } else if (elem.isJsonPrimitive()) { // wrapper.add(key, elem.getAsString()); wrapper.add(key, fromPrimitive((JsonPrimitive) elem)); } } } else if (json.isJsonArray()) { JsonArray array = json.getAsJsonArray(); for (JsonElement elem : array) { if (elem.isJsonPrimitive()) { wrapper.add(elem.toString(), ((JsonPrimitive) elem).getAsString()); } else if (elem.isJsonObject()) { wrapper.add(elem.toString(), deserializeFlatNameValue(elem, typeOfT, context)); } else if (elem.isJsonArray()) { wrapper.add(elem.toString(), deserializeFlatNameValue(elem, typeOfT, context)); } } } return wrapper; }