List of usage examples for com.google.gson JsonElement isJsonNull
public boolean isJsonNull()
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public java.util.Date getTime(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : new Date(LocalTime.parse(element.getAsString()).atDate(LocalDate.ofEpochDay(0L)) .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); }
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public byte[] getBytes(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : Base64.getDecoder().decode(element.getAsString()); }
From source file:com.adr.datasql.orm.KindResultsJson.java
License:Apache License
@Override public Object getObject(String columnName) throws DataLinkException { JsonElement element = json.get(columnName); return element == null || element.isJsonNull() ? null : element.getAsString(); }
From source file:com.apcb.utils.utils.HtmlTemplateReader.java
private SectionMatch readJson(JsonElement jsonElement, String from, SectionMatch sectionMatch) { //log.info(jsonElement.toString()); //SectionMatch sectionMatchChild = new SectionMatch(from); if (jsonElement.isJsonArray()) { //log.info("JsonArray"); JsonArray jsonArray = jsonElement.getAsJsonArray(); for (int i = 0; i < jsonArray.size(); i++) { SectionMatch sectionMatchArrayLevel = new SectionMatch(sectionMatch.getName()); sectionMatchArrayLevel.setIndex(i); sectionMatch.putChildens(readJson(jsonArray.get(i), from + "[" + i + "]", sectionMatchArrayLevel)); }// w w w. ja va 2 s .co m } else if (jsonElement.isJsonObject()) { //log.info("JsonObject"); JsonObject jsonObject = jsonElement.getAsJsonObject(); //since you know it's a JsonObject Set<Map.Entry<String, JsonElement>> entries = jsonObject.entrySet();//will return members of your object for (Map.Entry<String, JsonElement> entry : entries) { //log.info(entry.getKey()); sectionMatch.putChildens(readJson(jsonObject.get(entry.getKey()), from + "." + entry.getKey(), new SectionMatch(entry.getKey()))); } } else if (jsonElement.isJsonNull()) { log.info("JsonNull"); } else if (jsonElement.isJsonPrimitive()) { //log.info("JsonPrimitive"); String jsonVal = jsonElement.getAsString(); //from+= "."+entry.getKey(); sectionMatch.setValue(jsonVal); log.info(from + "=" + jsonVal); } return sectionMatch; }
From source file:com.apifest.AccessTokenValidator.java
License:Apache License
protected static String extractTokenScope(String tokenContent) { String scope = null;//from w w w. java2 s . c o m JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(tokenContent).getAsJsonObject(); JsonElement scopeElement = jsonObject.get("scope"); String rs = (scopeElement != null && !scopeElement.isJsonNull()) ? scopeElement.getAsString() : null; if (rs != null && !rs.toString().equals("null")) { scope = rs; } return scope; }
From source file:com.apifest.api.BasicAction.java
License:Apache License
/** * Extracts userId from tokenValidationResponse. * @param response the response received after access token is validate * @return userId associated with a token */// w w w. j a v a 2s . c om public static String getUserId(HttpResponse tokenValidationResponse) { String userId = null; if (tokenValidationResponse != null) { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(tokenValidationResponse.getContent().toString(CharsetUtil.UTF_8)) .getAsJsonObject(); JsonElement userIdElement = json.get("userId"); userId = (userIdElement != null && !userIdElement.isJsonNull()) ? userIdElement.getAsString() : null; } return userId; }
From source file:com.auth0.android.lock.internal.configuration.GsonDeserializer.java
License:Open Source License
void assertJsonObject(JsonElement jsonObject) throws JsonParseException { if (jsonObject.isJsonNull() || !jsonObject.isJsonObject()) { throw new JsonParseException("Received json is not a valid json object."); }/*w w w . jav a2s .c om*/ }
From source file:com.avapira.bobroreader.hanabira.entity.HanabiraEntity.java
License:Open Source License
private static LocalDateTime extractLocatDateTime(JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return null; } else {/*w ww . ja v a 2 s .co m*/ return LocalDateTime.parse(jsonElement.getAsString().replace(' ', 'T')); } }
From source file:com.balajeetm.mystique.core.ConditionMystTurn.java
License:Open Source License
/** * Checks if is equals./* ww w .j a va 2 s . c om*/ * * @param source the source * @param expected the expected * @return the boolean */ private Boolean isEquals(JsonElement source, JsonElement expected) { Boolean isEqual = Boolean.FALSE; // This is to check the existence case. The condition is to check the // existence of the element if (null == expected) { if (mystiqueLever.isNotNull(source)) { isEqual = Boolean.TRUE; } } else { if (mystiqueLever.isNull(source) && expected.isJsonNull()) { isEqual = Boolean.TRUE; } isEqual = expected.equals(source); } return isEqual; }
From source file:com.balajeetm.mystique.util.gson.lever.JsonLever.java
License:Open Source License
/** * Checks if is null.//from ww w . jav a 2 s . com * * @param source the source * @return the boolean */ public Boolean isNull(JsonElement source) { return null == source || source.isJsonNull(); }