List of usage examples for com.google.gson JsonPrimitive getAsJsonArray
public JsonArray getAsJsonArray()
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 ww.j a v a 2s . com*/ 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()); }// w w w .j av a2 s. c o m return values; } else { throw new IllegalArgumentException("value"); } }