List of usage examples for com.fasterxml.jackson.core JsonFactory createGenerator
public JsonGenerator createGenerator(Writer out) throws IOException
From source file:ch.rasc.wampspring.message.PrefixMessage.java
@Override public String toJson(JsonFactory jsonFactory) throws IOException { try (StringWriter sw = new StringWriter(); JsonGenerator jg = jsonFactory.createGenerator(sw)) { jg.writeStartArray();/* w ww .j a v a2 s . c o m*/ jg.writeNumber(getTypeId()); jg.writeString(this.prefix); jg.writeString(this.uri); jg.writeEndArray(); jg.close(); return sw.toString(); } }
From source file:org.dswarm.xsd2jsonschema.model.JSRoot.java
public void render(final JsonFactory jsonFactory, final Writer writer) throws IOException { render(jsonFactory.createGenerator(writer)); }
From source file:org.dswarm.xsd2jsonschema.model.JSRoot.java
public void render(final JsonFactory jsonFactory, final OutputStream out) throws IOException { render(jsonFactory.createGenerator(out)); }
From source file:org.apache.nutch.tools.CommonCrawlFormatJackson.java
public CommonCrawlFormatJackson(Configuration nutchConf, CommonCrawlConfig config) throws IOException { super(null, null, null, nutchConf, config); JsonFactory factory = new JsonFactory(); this.out = new ByteArrayOutputStream(); this.generator = factory.createGenerator(out); this.generator.useDefaultPrettyPrinter(); // INDENTED OUTPUT }
From source file:ch.rasc.wampspring.message.WelcomeMessage.java
@Override public String toJson(JsonFactory jsonFactory) throws IOException { try (StringWriter sw = new StringWriter(); JsonGenerator jg = jsonFactory.createGenerator(sw)) { jg.writeStartArray();//from w w w . ja va2 s . co m jg.writeNumber(getTypeId()); jg.writeString(this.sessionId); jg.writeNumber(this.protocolVersion); jg.writeString(this.serverIdent); jg.writeEndArray(); jg.close(); return sw.toString(); } }
From source file:org.apache.nutch.tools.CommonCrawlFormatJackson.java
public CommonCrawlFormatJackson(String url, Content content, Metadata metadata, Configuration nutchConf, CommonCrawlConfig config) throws IOException { super(url, content, metadata, nutchConf, config); JsonFactory factory = new JsonFactory(); this.out = new ByteArrayOutputStream(); this.generator = factory.createGenerator(out); this.generator.useDefaultPrettyPrinter(); // INDENTED OUTPUT }
From source file:javasnack.snacks.json.PojoEncodeJackson.java
@Override public void run() { ObjectMapper objectMapper = new ObjectMapper(); try {/* ww w. j a v a 2s. co m*/ String jsonout = objectMapper.writeValueAsString(new EncodePojo()); System.out.println("--- simple jackson encode ---"); System.out.println(jsonout); String jsonout2 = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(new EncodePojo()); System.out.println("--- default pretty-print jackson encode ---"); System.out.println(jsonout2); System.out.println("--- streaming jackson encode ---"); JsonFactory jsonFactory = objectMapper.getFactory(); Writer out = new OutputStreamWriter(System.out); JsonGenerator jg = jsonFactory.createGenerator(out); jg.setPrettyPrinter(new DefaultPrettyPrinter()); jg.writeStartObject(); jg.writeStringField("message", "success"); jg.writeNumberField("count", 10); jg.writeArrayFieldStart("records"); for (int i = 0; i < 10; i++) { jg.writeObject(new EncodePojo()); Thread.sleep(100); jg.flush(); } jg.writeEndArray(); jg.writeEndObject(); jg.close(); } catch (JsonProcessingException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ch.rasc.wampspring.message.EventMessage.java
@Override public String toJson(JsonFactory jsonFactory) throws IOException { try (StringWriter sw = new StringWriter(); JsonGenerator jg = jsonFactory.createGenerator(sw)) { jg.writeStartArray();//w ww. j a v a 2 s . c o m jg.writeNumber(getTypeId()); jg.writeString(getTopicURI()); jg.writeObject(this.event); jg.writeEndArray(); jg.close(); return sw.toString(); } }
From source file:ch.rasc.wampspring.message.CallErrorMessage.java
@Override public String toJson(JsonFactory jsonFactory) throws IOException { try (StringWriter sw = new StringWriter(); JsonGenerator jg = jsonFactory.createGenerator(sw)) { jg.writeStartArray();// w w w .j av a2s . c o m jg.writeNumber(getTypeId()); jg.writeString(this.callID); jg.writeString(this.errorURI); jg.writeString(this.errorDesc); if (this.errorDetails != null) { jg.writeObject(this.errorDetails); } jg.writeEndArray(); jg.close(); return sw.toString(); } }
From source file:ch.rasc.wampspring.message.CallMessage.java
@Override public String toJson(JsonFactory jsonFactory) throws IOException { try (StringWriter sw = new StringWriter(); JsonGenerator jg = jsonFactory.createGenerator(sw)) { jg.writeStartArray();//w ww . j a v a 2 s . c om jg.writeNumber(getTypeId()); jg.writeString(this.callID); jg.writeString(this.procURI); if (this.arguments != null) { for (Object argument : this.arguments) { jg.writeObject(argument); } } jg.writeEndArray(); jg.close(); return sw.toString(); } }