@Override public Object parse(String json) throws InvalidJsonException { try { return objectMapper.readTree(json); } catch (IOException e) { throw new InvalidJsonException(e, json); } }
@Override public Object apply(final String inputJson, final Options options) throws IOException { if (inputJson == null) { return ""; } if (options == null || options.param(0, null) == null) { return this.handleError("The JSONPath cannot be empty"); } final String jsonPath = options.param(0); try { Object result = JsonPath.read(inputJson, jsonPath); return JsonData.create(result); } catch (InvalidJsonException e) { return this.handleError( inputJson + " is not valid JSON", e.getJson(), e); } catch (JsonPathException e) { return this.handleError(jsonPath + " is not a valid JSONPath expression", e); } } }
@Override public Object parse(String json) throws InvalidJsonException { try { return objectReader.readValue(json); } catch (IOException e) { throw new InvalidJsonException(e, json); } }
@Override public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException { try { return objectMapper.readTree(new InputStreamReader(jsonStream, charset)); } catch (IOException e) { throw new InvalidJsonException(e); } }
@Override public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException { try { return objectReader.readValue(new InputStreamReader(jsonStream, charset)); } catch (IOException e) { throw new InvalidJsonException(e); } }
@Override public String toJson(Object obj) { StringWriter writer = new StringWriter(); try { JsonGenerator generator = objectMapper.getFactory().createGenerator(writer); objectMapper.writeValue(generator, obj); writer.flush(); writer.close(); generator.close(); return writer.getBuffer().toString(); } catch (IOException e) { throw new InvalidJsonException(e); } }
@Override public Object parse(String json) throws InvalidJsonException { try { return new JSONTokener(json).nextValue(); } catch (JSONException e) { throw new InvalidJsonException(e); } }
@Override public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException { try { return new JSONTokener(new InputStreamReader(jsonStream, charset)).nextValue(); } catch (UnsupportedEncodingException e) { throw new JsonPathException(e); } catch (JSONException e) { throw new InvalidJsonException(e); } }
@Override public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int size; while( (size=jsonStream.read(buffer))>0 ) { stream.write(buffer, 0, size); } return parse(new JettisonTokener(new String(stream.toByteArray(), charset))); } catch( IOException ioe ) { throw new InvalidJsonException(ioe); } }
public Object parse(String json) { try { return createParser().parse(json, mapper); } catch (ParseException e) { throw new InvalidJsonException(e); } }
@Override public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException { try { return createParser().parse(new InputStreamReader(jsonStream, charset), mapper); } catch (ParseException e) { throw new InvalidJsonException(e); } catch (UnsupportedEncodingException e) { throw new JsonPathException(e); } }
@Override public Object parse(String json) throws InvalidJsonException { try { return objectReader.readValue(json); } catch (IOException e) { throw new InvalidJsonException(e, json); } }
@Override public Object parse(String json) throws InvalidJsonException { try { return objectMapper.readTree(json); } catch (IOException e) { throw new InvalidJsonException(e, json); } }
@Override public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException { try { return objectMapper.readTree(new InputStreamReader(jsonStream, charset)); } catch (IOException e) { throw new InvalidJsonException(e); } }
@Override public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException { try { return objectReader.readValue(new InputStreamReader(jsonStream, charset)); } catch (IOException e) { throw new InvalidJsonException(e); } }
@Override public String toJson(Object obj) { StringWriter writer = new StringWriter(); try { JsonGenerator generator = objectMapper.getFactory().createGenerator(writer); objectMapper.writeValue(generator, obj); writer.flush(); writer.close(); generator.close(); return writer.getBuffer().toString(); } catch (IOException e) { throw new InvalidJsonException(); } }
@Override public Object parse(String json) throws InvalidJsonException { try { return new JSONTokener(json).nextValue(); } catch (JSONException e) { throw new InvalidJsonException(e); } }
@Override public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException { try { return new JSONTokener(new InputStreamReader(jsonStream, charset)).nextValue(); } catch (UnsupportedEncodingException e) { throw new JsonPathException(e); } catch (JSONException e) { throw new InvalidJsonException(e); } }
@Override public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int size; while( (size=jsonStream.read(buffer))>0 ) { stream.write(buffer, 0, size); } return parse(new JettisonTokener(new String(stream.toByteArray(), charset))); } catch( IOException ioe ) { throw new InvalidJsonException(ioe); } }
public Object parse(String json) { try { return createParser().parse(json, mapper); } catch (ParseException e) { throw new InvalidJsonException(e); } }