List of usage examples for com.fasterxml.jackson.core JsonGenerator close
@Override public abstract void close() throws IOException;
From source file:org.lansir.beautifulgirls.utils.JsonMapper.java
public static void node2json(JsonNode node, Writer w) throws JsonGenerationException, JsonMappingException, IOException { JsonGenerator jg = null; try {//from w w w . ja v a 2 s . c om jg = jf.createJsonGenerator(w); m.writeTree(jg, node); } finally { if (jg != null) { try { jg.close(); } catch (IOException e1) { } } } }
From source file:org.lansir.beautifulgirls.utils.JsonMapper.java
public static void pojo2Json(Object pojo, Writer w) throws JsonGenerationException, JsonMappingException, IOException { JsonGenerator jg = null; try {/*from w ww.ja v a2s . co m*/ jg = jf.createJsonGenerator(w); m.writeValue(jg, pojo); } finally { if (jg != null) { try { jg.close(); } catch (IOException e1) { } } } }
From source file:io.cslinmiso.line.utils.Utility.java
public static String bean2Json(Object obj) throws IOException { ObjectMapper mapper = new ObjectMapper(); StringWriter sw = new StringWriter(); JsonGenerator gen = new JsonFactory().createJsonGenerator(sw); mapper.writeValue(gen, obj);//from ww w.j a v a2 s . c o m gen.close(); return sw.toString(); }
From source file:com.microsoft.azure.storage.table.TableEntitySerializer.java
/** * Reserved for internal use. Writes an entity to the stream as a JSON resource, leaving the stream open * for additional writing./*from w w w . j a v a2 s . c o m*/ * * @param outStream * The <code>OutputStream</code> to write the entity to. * @param options * The {@link TableRequestOptions} to use for serializing. * @param entity * The instance implementing {@link TableEntity} to write to the output stream. * @param isTableEntry * A flag indicating the entity is a reference to a table at the top level of the storage service when * <code>true<code> and a reference to an entity within a table when <code>false</code>. * @param opContext * An {@link OperationContext} object used to track the execution of the operation. * * @throws StorageException * if a Storage service error occurs. * @throws IOException * if an error occurs while accessing the stream. */ static void writeSingleEntityToStream(final OutputStream outStream, final TableRequestOptions options, final TableEntity entity, final boolean isTableEntry, final OperationContext opContext) throws StorageException, IOException { JsonGenerator generator = Utility.getJsonGenerator(outStream); try { // write to stream writeJsonEntity(generator, options, entity, isTableEntry, opContext); } finally { generator.close(); } }
From source file:com.microsoft.azure.storage.table.TableEntitySerializer.java
/** * Reserved for internal use. Writes an entity to the stream as a JSON resource, leaving the stream open * for additional writing.//from w w w . j a v a 2 s . c o m * * @param strWriter * The <code>StringWriter</code> to write the entity to. * @param options * The {@link TableRequestOptions} to use for serializing. * @param entity * The instance implementing {@link TableEntity} to write to the output stream. * @param isTableEntry * A flag indicating the entity is a reference to a table at the top level of the storage service when * <code>true<code> and a reference to an entity within a table when <code>false</code>. * @param opContext * An {@link OperationContext} object used to track the execution of the operation. * * @throws StorageException * if a Storage service error occurs. * @throws IOException * if an error occurs while accessing the stream. */ static void writeSingleEntityToString(final StringWriter strWriter, final TableRequestOptions options, final TableEntity entity, final boolean isTableEntry, final OperationContext opContext) throws StorageException, IOException { JsonGenerator generator = Utility.getJsonGenerator(strWriter); try { // write to stream writeJsonEntity(generator, options, entity, isTableEntry, opContext); } finally { generator.close(); } }
From source file:org.lansir.beautifulgirls.utils.JsonMapper.java
public static String node2json(JsonNode node) throws JsonProcessingException, IOException { final StringWriter sw = new StringWriter(); JsonGenerator jg = null; try {//from w w w .j a v a 2s . c o m jg = jf.createJsonGenerator(sw); m.writeTree(jg, node); return sw.toString(); } finally { if (jg != null) { try { jg.close(); } catch (IOException e1) { } } } }
From source file:org.lansir.beautifulgirls.utils.JsonMapper.java
public static String pojo2json(Object pojo) throws JsonGenerationException, JsonMappingException, IOException { final StringWriter sw = new StringWriter(); JsonGenerator jg = null; try {/* w ww.j a va 2 s . c o m*/ jg = jf.createJsonGenerator(sw); m.writeValue(jg, pojo); return sw.toString(); } finally { if (jg != null) { try { jg.close(); } catch (IOException e1) { } } } }
From source file:com.teamlazerbeez.crm.sf.rest.HttpApiClientTest.java
private static String reformatJson(String input) throws IOException { JsonFactory jsonFactory = new JsonFactory(); JsonParser parser = jsonFactory.createJsonParser(input); StringWriter writer = new StringWriter(); JsonGenerator generator = jsonFactory.createJsonGenerator(writer); generator.useDefaultPrettyPrinter(); while (parser.nextToken() != null) { generator.copyCurrentEvent(parser); }//www .ja v a 2s. c o m generator.close(); return writer.toString(); }
From source file:com.palominolabs.crm.sf.rest.HttpApiClientTest.java
private static String reformatJson(@Nullable String input) throws IOException { checkNotNull(input);/*from w w w . j ava2 s . co m*/ JsonFactory jsonFactory = new JsonFactory(); JsonParser parser = jsonFactory.createParser(input); StringWriter writer = new StringWriter(); JsonGenerator generator = jsonFactory.createGenerator(writer); generator.useDefaultPrettyPrinter(); while (parser.nextToken() != null) { generator.copyCurrentEvent(parser); } generator.close(); return writer.toString(); }
From source file:io.seldon.spark.actions.JobUtils.java
public static String mapToJson(Map<String, String> m) { JsonFactory jsonFactory = new JsonFactory(); StringWriter sw = new StringWriter(); try {//from w w w .j av a2 s . c o m JsonGenerator jg = jsonFactory.createGenerator(sw); jg.writeStartObject(); for (Map.Entry<String, String> entry : m.entrySet()) { jg.writeStringField(entry.getKey(), entry.getValue()); } jg.writeEndObject(); jg.close(); } catch (IOException e) { e.printStackTrace(); } return sw.toString(); }