com.fasterxml.jackson.core.io.SegmentedStringWriter Java Examples
The following examples show how to use
com.fasterxml.jackson.core.io.SegmentedStringWriter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractContext.java From kripton with Apache License 2.0 | 6 votes |
@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(); }
Example #2
Source File: MessageMarshaller.java From curiostack with MIT License | 5 votes |
/** * Converts a {@link Message} into a JSON {@link String}. * * @throws InvalidProtocolBufferException if there are unknown Any types in the message. */ public <T extends Message> String writeValueAsString(T message) throws IOException { checkNotNull(message, "message"); SegmentedStringWriter sw = new SegmentedStringWriter(jsonFactory._getBufferRecycler()); try (JsonGenerator gen = jsonFactory.createGenerator(sw)) { writeValue(message, gen); } return sw.getAndClear(); }
Example #3
Source File: AbstractContext.java From kripton with Apache License 2.0 | 5 votes |
@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(); }
Example #4
Source File: ContextualStoredAsJsonSerializer.java From Rosetta with Apache License 2.0 | 5 votes |
private String serializeToString(T value, ObjectMapper mapper, SerializerProvider provider) throws IOException { try (SegmentedStringWriter sw = new SegmentedStringWriter(new BufferRecycler())) { if (trySerializeToWriter(value, mapper, provider, sw)) { return sw.getAndClear(); } } // fallback on old behavior JsonNode tree = mapper.valueToTree(value); if (tree.isNull()) { return tree.asText(); } else { return mapper.writeValueAsString(tree); } }
Example #5
Source File: JSONComposer.java From jackson-jr with Apache License 2.0 | 5 votes |
protected JSONComposer(int features, JsonGenerator gen, SegmentedStringWriter w) { super(gen); _features = features; _stringWriter = w; _byteWriter = null; _closeGenerator = true; }
Example #6
Source File: JSONComposer.java From jackson-jr with Apache License 2.0 | 4 votes |
public static JSONComposer<String> stringComposer(int features, JsonGenerator gen, SegmentedStringWriter w) { return new JSONComposer<String>(features, gen, w); }
Example #7
Source File: JSON.java From jackson-jr with Apache License 2.0 | 4 votes |
public JSONComposer<String> composeString() throws IOException, JSONObjectException { SegmentedStringWriter out = new SegmentedStringWriter(_streamFactory._getBufferRecycler()); JsonGenerator gen = _config(_streamFactory.createGenerator(this, out)); return JSONComposer.stringComposer(_features, gen, out); }