Пример #1
0
  private void process(File input) throws IOException {
    JsonFactory jsonF = new JsonFactory();
    JsonParser jp = jsonF.createJsonParser(input);
    TwitterEntry entry = read(jp);

    // let's write to a file, using UTF-8 encoding (only sensible one)
    StringWriter strw = new StringWriter();
    JsonGenerator jg = jsonF.createJsonGenerator(strw);
    jg.useDefaultPrettyPrinter(); // enable indentation just to make debug/testing easier

    // Here we would modify it... for now, will just (re)indent it

    write(jg, entry);

    System.out.println("Result = [" + strw.toString() + "]");
  }
Пример #2
0
 /**
  * Helper method called to set or override settings of passed-in {@link JsonGenerator}
  *
  * @since 2.1
  */
 private final void _configureJsonGenerator(JsonGenerator jgen) {
   if (_prettyPrinter != null) {
     PrettyPrinter pp = _prettyPrinter;
     if (pp == NULL_PRETTY_PRINTER) {
       jgen.setPrettyPrinter(null);
     } else {
       /* [JACKSON-851]: Better take care of stateful PrettyPrinters...
        *   like the DefaultPrettyPrinter.
        */
       if (pp instanceof Instantiatable<?>) {
         pp = (PrettyPrinter) ((Instantiatable<?>) pp).createInstance();
       }
       jgen.setPrettyPrinter(pp);
     }
   } else if (_config.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
     jgen.useDefaultPrettyPrinter();
   }
   // [JACKSON-520]: add support for pass-through schema:
   if (_schema != null) {
     jgen.setSchema(_schema);
   }
 }