/** * Returns the next available {@link JsonElement} on the reader. Null if none available. * * @return the next available {@link JsonElement} on the reader. Null if none available. * @throws JsonParseException if the incoming stream is malformed JSON. * @since 1.4 */ public JsonElement next() throws JsonParseException { if (!hasNext()) { throw new NoSuchElementException(); } try { return Streams.parse(parser); } catch (StackOverflowError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (JsonParseException e) { throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e; } }
/** * Returns the next available {@link JsonElement} on the reader. Null if none available. * * @return the next available {@link JsonElement} on the reader. Null if none available. * @throws JsonParseException if the incoming stream is malformed JSON. * @since 1.4 */ public JsonElement next() throws JsonParseException { if (!hasNext()) { throw new NoSuchElementException(); } try { return Streams.parse(parser); } catch (StackOverflowError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (JsonParseException e) { throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e; } }
/** * Returns the next available {@link JsonElement} on the reader. Null if none available. * * @return the next available {@link JsonElement} on the reader. Null if none available. * @throws JsonParseException if the incoming stream is malformed JSON. * @since 1.4 */ public JsonElement next() throws JsonParseException { if (!hasNext()) { throw new NoSuchElementException(); } try { return Streams.parse(parser); } catch (StackOverflowError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (JsonParseException e) { throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e; } }
/** * Returns the next available {@link JsonElement} on the reader. Null if none available. * * @return the next available {@link JsonElement} on the reader. Null if none available. * @throws JsonParseException if the incoming stream is malformed JSON. * @since 1.4 */ public JsonElement next() throws JsonParseException { if (!hasNext()) { throw new NoSuchElementException(); } try { return Streams.parse(parser); } catch (StackOverflowError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (JsonParseException e) { throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e; } }
/** * Returns the next available {@link JsonElement} on the reader. Null if none available. * * @return the next available {@link JsonElement} on the reader. Null if none available. * @throws JsonParseException if the incoming stream is malformed JSON. * @since 1.4 */ public JsonElement next() throws JsonParseException { if (!hasNext()) { throw new NoSuchElementException(); } try { return Streams.parse(parser); } catch (StackOverflowError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (JsonParseException e) { throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e; } }
/** * Returns the next available {@link JsonElement} on the reader. Null if none available. * * @return the next available {@link JsonElement} on the reader. Null if none available. * @throws JsonParseException if the incoming stream is malformed JSON. * @since 1.4 */ public JsonElement next() throws JsonParseException { if (!hasNext()) { throw new NoSuchElementException(); } try { return Streams.parse(parser); } catch (StackOverflowError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (JsonParseException e) { throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e; } }
/** * Returns the next available {@link JsonElement} on the reader. Null if none available. * * @return the next available {@link JsonElement} on the reader. Null if none available. * @throws JsonParseException if the incoming stream is malformed JSON. * @since 1.4 */ public JsonElement next() throws JsonParseException { if (!hasNext()) { throw new NoSuchElementException(); } try { return Streams.parse(parser); } catch (StackOverflowError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (JsonParseException e) { throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e; } }
/** * Returns the next available {@link JsonElement} on the reader. Null if none available. * * @return the next available {@link JsonElement} on the reader. Null if none available. * @throws JsonParseException if the incoming stream is malformed JSON. * @since 1.4 */ public JsonElement next() throws JsonParseException { if (!hasNext()) { throw new NoSuchElementException(); } try { return Streams.parse(parser); } catch (StackOverflowError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (JsonParseException e) { throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e; } }
@Override public T transformData(InputStream inputStream, ImmutableHttpRequest request) throws IOException, ParserException { String dataString = null; if (debugData) { dataString = XferTransformInputStreamString.INSTANCE.transformData(inputStream, request); inputStream = new ByteArrayInputStream(dataString.getBytes()); } Charset readCharset = CharsetUtils.getInputCharsetOrUtf8(request.getHttpResponse()); InputStreamReader ir = new InputStreamReader(inputStream, readCharset); try { JsonReader reader = new JsonReader(ir); return gson.fromJson(reader, type); } catch (JsonParseException e) { if (e.getCause() instanceof IOException) throw (IOException) e.getCause(); throw new ParserException("Bad data for GSON", e, dataString); } finally { try { ir.close(); } catch (IOException ignored) { } } }
/** * Returns the next value from the JSON stream as a parse tree. * * @throws JsonParseException if there is an IOException or if the specified * text is not valid JSON * @since 1.6 */ 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); } catch (JsonParseException e) { if (e.getCause() instanceof EOFException) { return JsonNull.INSTANCE; } throw e; } finally { json.setLenient(lenient); } } }
/** * Returns the next value from the JSON stream as a parse tree. * * @throws JsonParseException if there is an IOException or if the specified * text is not valid JSON * @since 1.6 */ 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); } catch (JsonParseException e) { if (e.getCause() instanceof EOFException) { return JsonNull.INSTANCE; } throw e; } finally { json.setLenient(lenient); } } }
@Override public DataModelReflection next() throws IOException { if (first) { try { parser.hasNext(); } catch (JsonParseException e) { if (e.getCause() instanceof EOFException) { return null; } } first = false; } try { if (parser.hasNext() == false) { return null; } JsonElement element = parser.next(); return JsonObjectDriver.convert(definition, element); } catch (JsonParseException e) { throw new IOException(MessageFormat.format( Messages.getString("JsonDataModelSource.errorMalformedJsonObject"), //$NON-NLS-1$ id), e); } }