@Override public void copyCurrentEvent(JsonParser p) throws IOException { if (delegateCopyMethods) delegate.copyCurrentEvent(p); else super.copyCurrentEvent(p); }
@Override public void copyCurrentEvent(JsonParser p) throws IOException { if (delegateCopyMethods) delegate.copyCurrentEvent(p); else super.copyCurrentEvent(p); }
throw invalidJson("bad start token: " + token); generator.copyCurrentEvent(parser); generator.copyCurrentEvent(parser); break;
break; default: copyCurrentEvent(p);
break; default: copyCurrentEvent(p);
@Override public void copyCurrentEvent(JsonParser p) throws IOException { if (delegateCopyMethods) delegate.copyCurrentEvent(p); else super.copyCurrentEvent(p); }
@Override public void copyCurrentEvent(JsonParser jp) throws IOException { if (delegateCopyMethods) delegate.copyCurrentEvent(jp); else super.copyCurrentEvent(jp); }
@Override public void copyCurrentEvent(JsonParser jp) throws IOException { if (delegateCopyMethods) delegate.copyCurrentEvent(jp); else super.copyCurrentEvent(jp); }
@Override public void copyCurrentEvent(JsonParser jp) throws IOException { if (delegateCopyMethods) delegate.copyCurrentEvent(jp); else super.copyCurrentEvent(jp); }
@Override public void copyCurrentEvent(JsonParser jp) throws IOException, JsonProcessingException { delegate.copyCurrentEvent(jp); }
@Override public void copyCurrentEvent(JsonParser jp) throws IOException, JsonProcessingException { delegate.copyCurrentEvent(jp); }
// source and out can be streams, readers/writers, etc. String source = " { \"hello\" : \" world \" } "; StringWriter out = new StringWriter(); JsonFactory factory = new JsonFactory(); JsonParser parser = factory.createParser(source); try (JsonGenerator gen = factory.createGenerator(out)) { while (parser.nextToken() != null) { gen.copyCurrentEvent(parser); } } System.out.println(out.getBuffer().toString()); // {"hello":" world "}
String compact(final String json) throws IOException { final StringWriter output = new StringWriter(json.length()); final JsonFactory factory = mapper.getFactory(); final JsonParser parser = factory.createParser(json); final JsonGenerator generator = factory.createGenerator(output); // https://github.com/jacoco/jacoco/wiki/FilteringOptions //noinspection TryFinallyCanBeTryWithResources - jacoco can't handle try-with correctly try { while (parser.nextToken() != null) { generator.copyCurrentEvent(parser); } } finally { generator.close(); } return output.toString(); }
String compact(final String json) throws IOException { final StringWriter output = new StringWriter(json.length()); final JsonFactory factory = mapper.getFactory(); final JsonParser parser = factory.createParser(json); final JsonGenerator generator = factory.createGenerator(output); // https://github.com/jacoco/jacoco/wiki/FilteringOptions //noinspection TryFinallyCanBeTryWithResources - jacoco can't handle try-with correctly try { while (parser.nextToken() != null) { generator.copyCurrentEvent(parser); } } finally { generator.close(); } return output.toString(); }
private byte[] _indent(byte[] rawJson) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream((rawJson.length * 3) / 2); JsonParser jp = jsonFactory.createParser(rawJson); JsonGenerator jg = jsonFactory.createGenerator(out); jg.useDefaultPrettyPrinter(); while (jp.nextToken() != null) { jg.copyCurrentEvent(jp); } jp.close(); jg.close(); return out.toByteArray(); } }
public static byte[] removeKeys(byte[] source, List<String> keys) throws IOException { Collections.sort(keys); ByteArrayOutputStream out = new ByteArrayOutputStream(); JsonParser p = JsonFactoryImpl.INSTANCE.getParser(source); JsonGenerator g = JsonFactoryImpl.INSTANCE.getGenerator(out); JsonToken t = p.nextToken(); while(t != null) { String currentName = p.getCurrentName(); if (currentName == null || Collections.binarySearch(keys, currentName) < 0) { g.copyCurrentEvent(p); } t = p.nextToken(); } p.close(); g.flush(); g.close(); return out.toByteArray(); }
private void extractSubcomponents() throws IOException { ByteArrayOutputStream baseOut = new ByteArrayOutputStream(); JsonParser p = this.getParser(); JsonGenerator g = this.getGenerator(baseOut); JsonToken t; t = p.nextToken(); while (t != null) { String currentName = p.getCurrentName(); if(currentName != null && t == JsonToken.FIELD_NAME && currentName.equals("timeSeries")) { p.nextToken(); p.skipChildren(); } else { g.copyCurrentEvent(p); } t = p.nextToken(); } p.close(); g.flush(); g.close(); this.component = baseOut.toByteArray(); } }
private void extractSubcomponents() throws IOException { ByteArrayOutputStream baseOut = new ByteArrayOutputStream(); JsonParser p = this.getParser(); JsonGenerator g = this.getGenerator(baseOut); JsonToken t; t = p.nextToken(); while (t != null) { String currentName = p.getCurrentName(); if(currentName != null && t == JsonToken.FIELD_NAME && currentName.equals("soilLayer")) { p.nextToken(); p.skipChildren(); } else { g.copyCurrentEvent(p); } t = p.nextToken(); } p.close(); g.flush(); g.close(); this.component = baseOut.toByteArray(); baseOut = null; } }
private void extractSubcomponents() throws IOException { ByteArrayOutputStream baseOut = new ByteArrayOutputStream(); JsonParser p = this.getParser(); JsonGenerator g = this.getGenerator(baseOut); JsonToken t; t = p.nextToken(); while (t != null) { String currentName = p.getCurrentName(); if(currentName != null && t == JsonToken.FIELD_NAME && currentName.equals("dailyWeather")) { p.nextToken(); p.skipChildren(); } else { g.copyCurrentEvent(p); } t = p.nextToken(); } p.close(); g.flush(); g.close(); this.component = baseOut.toByteArray(); this.getId(true); baseOut = null; }
private void extractSubcomponents() throws IOException { ByteArrayOutputStream baseOut = new ByteArrayOutputStream(); JsonParser p = this.getParser(); JsonGenerator g = this.getGenerator(baseOut); JsonToken t; t = p.nextToken(); while (t != null) { String currentName = p.getCurrentName(); if(currentName != null && t == JsonToken.FIELD_NAME && currentName.equals("soilLayer")) { p.nextToken(); p.skipChildren(); } else { g.copyCurrentEvent(p); } t = p.nextToken(); } p.close(); g.flush(); g.close(); this.component = baseOut.toByteArray(); this.getId(true); baseOut = null; }