List of usage examples for com.google.gson.internal LazilyParsedNumber LazilyParsedNumber
public LazilyParsedNumber(String value)
From source file:json.tests.parser.JSONDeferredParser.java
License:Open Source License
public JsonElement read(String elementName) { try {//from ww w.j a va 2 s . co m switch (this.reader.peek()) { case STRING: return new JsonPrimitive(this.reader.nextString()); case NUMBER: String number = this.reader.nextString(); return new JsonPrimitive(new LazilyParsedNumber(number)); case BOOLEAN: return new JsonPrimitive(this.reader.nextBoolean()); case NULL: this.reader.nextNull(); return JsonNull.INSTANCE; case BEGIN_ARRAY: JsonArray array = new JsonArray(); this.reader.beginArray(); while (this.reader.hasNext()) { array.add(read(elementName)); } this.reader.endArray(); return array; case BEGIN_OBJECT: if (element.isJsonArray()) { element.getAsJsonArray().get(0); } JsonObject object = new JsonObject(); this.reader.beginObject(); String childName; while (this.reader.hasNext()) { childName = this.reader.nextName(); elementStack.add(childName); object.add(childName, read(elementName)); if (this.found || elementName.equals(childName)) { return object; } } this.reader.endObject(); return object; case END_DOCUMENT: case NAME: case END_OBJECT: case END_ARRAY: default: throw new IllegalArgumentException(); } } catch (IOException e) { e.printStackTrace(); } // we never reach here. Returning null just to make the compiler happy. return null; }
From source file:org.opendaylight.controller.sal.rest.gson.JsonParser.java
License:Open Source License
public JsonElement read(JsonReader in) throws IOException { switch (in.peek()) { case STRING:/*w ww. j a va2s . c o m*/ return new JsonPrimitive(in.nextString()); case NUMBER: String number = in.nextString(); return new JsonPrimitive(new LazilyParsedNumber(number)); case BOOLEAN: return new JsonPrimitive(in.nextBoolean()); case NULL: in.nextNull(); return JsonNull.INSTANCE; case BEGIN_ARRAY: JsonArray array = new JsonArray(); in.beginArray(); while (in.hasNext()) { array.add(read(in)); } in.endArray(); return array; case BEGIN_OBJECT: JsonObject object = new JsonObject(); in.beginObject(); while (in.hasNext()) { final String childName = in.nextName(); if (object.has(childName)) { throw new JsonSyntaxException("Duplicate name " + childName + " in JSON input."); } object.add(childName, read(in)); } in.endObject(); return object; case END_DOCUMENT: case NAME: case END_OBJECT: case END_ARRAY: default: throw new IllegalArgumentException(); } }