Example #1
0
 public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException {
   boolean lenient = json.isLenient();
   json.setLenient(true);
   try {
     return Streams.parse(json);
   } catch (StackOverflowError e) {
     throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
   } catch (OutOfMemoryError e) {
     throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
   } finally {
     json.setLenient(lenient);
   }
 }
Example #2
0
 public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
   try {
     JsonReader jsonReader = new JsonReader(json);
     JsonElement element = parse(jsonReader);
     if ((!element.isJsonNull()) && (jsonReader.peek() != JsonToken.END_DOCUMENT)) {
       throw new JsonSyntaxException("Did not consume the entire document.");
     }
     return element;
   } catch (MalformedJsonException e) {
     throw new JsonSyntaxException(e);
   } catch (IOException e) {
     throw new JsonIOException(e);
   } catch (NumberFormatException e) {
     throw new JsonSyntaxException(e);
   }
 }