/** * Method that can be used to serialize any Java value as * a String. Functionally equivalent to calling * {@link #writeValue(Writer,Object)} with {@link java.io.StringWriter} * and constructing String, but more efficient. *<p> * Note: prior to version 2.1, throws clause included {@link IOException}; 2.1 removed it. */ @SuppressWarnings("resource") public String writeValueAsString(Object value) throws JsonProcessingException { // alas, we have to pull the recycler directly here... SegmentedStringWriter sw = new SegmentedStringWriter(_generatorFactory._getBufferRecycler()); try { _configAndWriteValue(_generatorFactory.createGenerator(sw), value); } catch (JsonProcessingException e) { throw e; } catch (IOException e) { // shouldn't really happen, but is declared as possibility so: throw JsonMappingException.fromUnexpectedIOE(e); } return sw.getAndClear(); }
@Override public Writer append(char c) { write(c); return this; }
public String writeEventAsString(Event event) throws IOException { SegmentedStringWriter writer = new SegmentedStringWriter(getBufferRecycler()); JsonGenerator generator = createGenerator(writer); writeEventToGenerator(generator, event); writer.flush(); return writer.getAndClear(); }
@Override public String _writeAsString(MeasurementPOJO items) throws Exception { try (JsonGenerator g = _jsonFactory.createGenerator(_writer)) { items.writeTo(g); return _writer.getAndClear(); } } }
public DZoneManualWJackson() { _jsonFactory = new JsonFactory(); _writer = new SegmentedStringWriter(new BufferRecycler()); }
/** * Method that can be used to serialize any Java value as * a String. Functionally equivalent to calling * {@link #writeValue(Writer,Object)} with {@link java.io.StringWriter} * and constructing String, but more efficient. *<p> * Note: prior to version 2.1, throws clause included {@link IOException}; 2.1 removed it. */ @SuppressWarnings("resource") public String writeValueAsString(Object value) throws JsonProcessingException { // alas, we have to pull the recycler directly here... SegmentedStringWriter sw = new SegmentedStringWriter(_jsonFactory._getBufferRecycler()); try { _configAndWriteValue(_jsonFactory.createGenerator(sw), value); } catch (JsonProcessingException e) { throw e; } catch (IOException e) { // shouldn't really happen, but is declared as possibility so: throw JsonMappingException.fromUnexpectedIOE(e); } return sw.getAndClear(); }
@Override public Writer append(char c) { write(c); return this; }
@Override public String writeValueAsString(Object value) throws JsonProcessingException { // alas, we have to pull the recycler directly here... SegmentedStringWriter sw = new SegmentedStringWriter(_jsonFactory._getBufferRecycler()); try { JsonGenerator ge = _jsonFactory.createGenerator(sw); // set ethereum custom pretty printer EtherPrettyPrinter pp = new EtherPrettyPrinter(); ge.setPrettyPrinter(pp); _configAndWriteValue(ge, value); } catch (JsonProcessingException e) { // to support [JACKSON-758] throw e; } catch (IOException e) { // shouldn't really happen, but is declared as possibility so: throw JsonMappingException.fromUnexpectedIOE(e); } return sw.getAndClear(); }
@Override public Writer append(char c) { write(c); return this; }
/** * Method that can be used to serialize any Java value as * a String. Functionally equivalent to calling * {@link #writeValue(Writer,Object)} with {@link java.io.StringWriter} * and constructing String, but more efficient. */ public String writeValueAsString(Object value) throws IOException, JsonGenerationException, JsonMappingException { // alas, we have to pull the recycler directly here... SegmentedStringWriter sw = new SegmentedStringWriter(_jsonFactory._getBufferRecycler()); _configAndWriteValue(_jsonFactory.createJsonGenerator(sw), value); return sw.getAndClear(); }
@Override public Writer append(char c) { write(c); return this; }
/** * Method that can be used to serialize any Java value as * a String. Functionally equivalent to calling * {@link #writeValue(Writer,Object)} with {@link java.io.StringWriter} * and constructing String, but more efficient. */ public String writeValueAsString(Object value) throws IOException, JsonGenerationException, JsonMappingException { // alas, we have to pull the recycler directly here... SegmentedStringWriter sw = new SegmentedStringWriter(_jsonFactory._getBufferRecycler()); _configAndWriteValue(_jsonFactory.createJsonGenerator(sw), value); return sw.getAndClear(); }
@Override public Writer append(char c) { write(c); return this; }
@Override public <E> String serializeCollection(Collection<E> collection, Class<E> objectClazz) { if (collection == null) return null; SegmentedStringWriter source = new SegmentedStringWriter(buffer.get()); try (SerializerWrapper serializer = createSerializer(source)) { mapperFor(objectClazz).serializeCollection(this, serializer, collection); } catch (Exception e) { e.printStackTrace(); throw new KriptonRuntimeException(e); } return source.getAndClear(); }
@Override public Writer append(char c) { write(c); return this; }
@SuppressWarnings("unchecked") @Override public <E> String serialize(E object) { if (object == null) return null; SegmentedStringWriter source = new SegmentedStringWriter(buffer.get()); try (SerializerWrapper serializer = createSerializer(source)) { mapperFor((Class<E>) object.getClass()).serialize(this, serializer, object); } catch (Exception e) { e.printStackTrace(); throw new KriptonRuntimeException(e); } return source.getAndClear(); }
@Override public Writer append(char c) { write(c); return this; }
@SuppressWarnings("unchecked") @Override public <E> String serialize(E object) { if (object == null) return null; SegmentedStringWriter source = new SegmentedStringWriter(buffer.get()); try (SerializerWrapper serializer = createSerializer(source)) { mapperFor((Class<E>) object.getClass()).serialize(this, serializer, object); } catch (Exception e) { e.printStackTrace(); throw new KriptonRuntimeException(e); } return source.getAndClear(); }
@Override public Writer append(char c) { write(c); return this; }
@Override public <E> String serializeCollection(Collection<E> collection, Class<E> objectClazz) { if (collection == null) return null; SegmentedStringWriter source = new SegmentedStringWriter(buffer.get()); try (SerializerWrapper serializer = createSerializer(source)) { mapperFor(objectClazz).serializeCollection(this, serializer, collection); } catch (Exception e) { e.printStackTrace(); throw new KriptonRuntimeException(e); } return source.getAndClear(); }