List of usage examples for com.google.gson JsonElement isJsonNull
public boolean isJsonNull()
From source file:co.cask.cdap.internal.app.ProcedureSpecificationCodec.java
License:Apache License
@Override public ProcedureSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String className = jsonObj.get("className").getAsString(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); Set<String> dataSets = deserializeSet(jsonObj.get("datasets"), context, String.class); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); ResourceSpecification resourceSpec = context.deserialize(jsonObj.get("resources"), new TypeToken<ResourceSpecification>() { }.getType());/* w w w . j a v a 2 s . co m*/ JsonElement instanceElem = jsonObj.get("instances"); int instances = (instanceElem == null || instanceElem.isJsonNull()) ? 1 : jsonObj.get("instances").getAsInt(); return new DefaultProcedureSpecification(className, name, description, dataSets, properties, resourceSpec, instances); }
From source file:co.vaughnvernon.tradercommon.media.AbstractJSONMediaReader.java
License:Apache License
protected JsonElement navigateTo(JsonObject aStartingJsonObject, String... aKeys) { if (aKeys.length == 0) { throw new IllegalArgumentException("Must specify one or more keys."); } else if (aKeys.length == 1 && (aKeys[0].startsWith("/") || aKeys[0].contains("."))) { aKeys = this.parsePath(aKeys[0]); }//from ww w.j a v a 2 s .c o m int keyIndex = 1; JsonElement element = this.elementFrom(aStartingJsonObject, aKeys[0]); if (!element.isJsonNull() && !element.isJsonPrimitive() && !element.isJsonArray()) { JsonObject object = element.getAsJsonObject(); for (; element != null && !element.isJsonPrimitive() && keyIndex < aKeys.length; ++keyIndex) { element = this.elementFrom(object, aKeys[keyIndex]); if (!element.isJsonPrimitive()) { element = this.elementFrom(object, aKeys[keyIndex]); if (element.isJsonNull()) { element = null; } else { object = element.getAsJsonObject(); } } } } if (element != null) { if (!element.isJsonNull()) { if (keyIndex != aKeys.length) { throw new IllegalArgumentException("Last name must reference a simple value."); } } else { element = null; } } return element; }
From source file:com.addthis.hydra.task.source.bundleizer.GsonBundleizer.java
License:Apache License
public ValueObject fromGson(JsonElement gson) { if (gson.isJsonNull()) { return null; } else if (gson.isJsonObject()) { JsonObject object = gson.getAsJsonObject(); ValueMap map = ValueFactory.createMap(); for (Map.Entry<String, JsonElement> entry : object.entrySet()) { map.put(entry.getKey(), fromGson(entry.getValue())); }//from w ww.j a va 2 s . c om return map; } else if (gson.isJsonArray()) { JsonArray gsonArray = gson.getAsJsonArray(); ValueArray valueArray = ValueFactory.createArray(gsonArray.size()); for (JsonElement arrayElement : gsonArray) { valueArray.add(fromGson(arrayElement)); } return valueArray; } else { JsonPrimitive primitive = gson.getAsJsonPrimitive(); if (primitive.isNumber()) { return ValueFactory.create(primitive.getAsDouble()); } else { return ValueFactory.create(primitive.getAsString()); } } }
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public Integer getInt(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : element.getAsInt(); }
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public String getString(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : element.getAsString(); }
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public Double getDouble(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : element.getAsDouble(); }
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public BigDecimal getBigDecimal(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : element.getAsBigDecimal(); }
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public Boolean getBoolean(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : element.getAsBoolean(); }
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public java.util.Date getTimestamp(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : new Date(Instant.parse(element.getAsString()).toEpochMilli()); }
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public java.util.Date getDate(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : new Date(LocalDate.parse(element.getAsString()).atStartOfDay(ZoneId.systemDefault()).toInstant() .toEpochMilli());//ww w . j av a 2 s .com }