List of usage examples for com.google.gson JsonPrimitive isJsonArray
public boolean isJsonArray()
From source file:org.faul.jql.utils.RemoteObjectHandler.java
License:Open Source License
Object getPrimitive(JsonPrimitive p) { if (p.isNumber()) { String str = p.getAsString(); try {// w w w . ja v a2 s . co m return Long.parseLong(str); } catch (Exception error) { } return Double.parseDouble(str); } if (p.isBoolean()) { return p.getAsBoolean(); } if (p.isJsonArray()) { return p.getAsJsonArray(); } if (p.isString()) { return p.getAsString(); } return null; }
From source file:org.gogoup.dddutils.misc.CodingHelper.java
License:Apache License
public static Object getObjectFromJson(JsonPrimitive value) { if (value.isString()) { return value.getAsString(); } else if (value.isBoolean()) { return value.getAsBoolean(); } else if (value.isNumber()) { return value.getAsNumber(); } else if (value.isJsonNull()) { return null; } else if (value.isJsonArray()) { JsonArray objArray = value.getAsJsonArray(); Object[] values = new Object[objArray.size()]; for (int i = 0; i < values.length; i++) { values[i] = getObjectFromJson(objArray.get(i).getAsJsonPrimitive()); }/*from w w w . j av a 2 s. c o m*/ return values; } else { throw new IllegalArgumentException("value"); } }