use of com.fasterxml.jackson.databind.util.TokenBuffer in project jackson-databind by FasterXML.
the class TestJacksonTypes method testTokenBuffer.
/**
* Verify that {@link TokenBuffer} can be properly serialized
* automatically, using the "standard" JSON sample document
*/
public void testTokenBuffer() throws Exception {
// First, copy events from known good source (StringReader)
JsonParser jp = createParserUsingReader(SAMPLE_DOC_JSON_SPEC);
TokenBuffer tb = new TokenBuffer(null, false);
while (jp.nextToken() != null) {
tb.copyCurrentEvent(jp);
}
jp.close();
// Then serialize as String
String str = serializeAsString(tb);
tb.close();
// and verify it looks ok
verifyJsonSpecSampleDoc(createParserUsingReader(str), true);
}
use of com.fasterxml.jackson.databind.util.TokenBuffer in project java by wavefrontHQ.
the class JsonMetricsGenerator method generateJsonMetrics.
public static JsonNode generateJsonMetrics(MetricsRegistry registry, boolean includeVMMetrics, boolean includeBuildMetrics, boolean clearMetrics, @Nullable Map<String, String> pointTags, @Nullable MetricTranslator metricTranslator) throws IOException {
TokenBuffer t = new TokenBuffer(new ObjectMapper(), false);
writeJson(t, registry, includeVMMetrics, includeBuildMetrics, clearMetrics, pointTags, metricTranslator);
JsonParser parser = t.asParser();
return parser.readValueAsTree();
}
use of com.fasterxml.jackson.databind.util.TokenBuffer in project jackson-jaxrs-propertyfiltering by HubSpot.
the class PropertyFilteringMessageBodyWriter method valueToTree.
private JsonNode valueToTree(ObjectMapper mapper, ObjectWriter writer, Object o) {
if (o == null) {
return null;
}
TokenBuffer buf = new TokenBuffer(mapper, false);
JsonNode result;
try {
writer.writeValue(buf, o);
JsonParser jp = buf.asParser();
result = mapper.readTree(jp);
jp.close();
} catch (IOException e) {
// should not occur, no real i/o...
throw new IllegalArgumentException(e.getMessage(), e);
}
return result;
}
use of com.fasterxml.jackson.databind.util.TokenBuffer in project drill by apache.
the class DrillValuesRelBase method convertToJsonNode.
private static JsonNode convertToJsonNode(RelDataType rowType, List<? extends List<RexLiteral>> tuples) throws IOException {
TokenBuffer out = new TokenBuffer(MAPPER.getFactory().getCodec(), false);
JsonOutput json = new ExtendedJsonOutput(out);
json.writeStartArray();
String[] fields = rowType.getFieldNames().toArray(new String[rowType.getFieldCount()]);
for (List<RexLiteral> row : tuples) {
json.writeStartObject();
int i = 0;
for (RexLiteral field : row) {
json.writeFieldName(fields[i]);
writeLiteral(field, json);
i++;
}
json.writeEndObject();
}
json.writeEndArray();
json.flush();
return out.asParser().readValueAsTree();
}
use of com.fasterxml.jackson.databind.util.TokenBuffer in project spring-framework by spring-projects.
the class AbstractJackson2Decoder method decode.
@Override
public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
ObjectMapper mapper = selectObjectMapper(elementType, mimeType);
if (mapper == null) {
throw new IllegalStateException("No ObjectMapper for " + elementType);
}
boolean forceUseOfBigDecimal = mapper.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
if (BigDecimal.class.equals(elementType.getType())) {
forceUseOfBigDecimal = true;
}
Flux<DataBuffer> processed = processInput(input, elementType, mimeType, hints);
Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(processed, mapper.getFactory(), mapper, true, forceUseOfBigDecimal, getMaxInMemorySize());
ObjectReader reader = getObjectReader(mapper, elementType, hints);
return tokens.handle((tokenBuffer, sink) -> {
try {
Object value = reader.readValue(tokenBuffer.asParser(mapper));
logValue(value, hints);
if (value != null) {
sink.next(value);
}
} catch (IOException ex) {
sink.error(processException(ex));
}
});
}
Aggregations