use of com.fasterxml.jackson.databind.ObjectWriter in project pinpoint by naver.
the class LinkSerializerTest method testSerialize.
@Test
public void testSerialize() throws Exception {
AgentHistogramList list = new AgentHistogramList();
AgentHistogram histogram = new AgentHistogram(new Application("test", ServiceType.STAND_ALONE));
list.addAgentHistogram(histogram);
Node node1 = new Node(new Application("test1", ServiceType.STAND_ALONE));
Node node2 = new Node(new Application("test1", ServiceType.STAND_ALONE));
Link link = new Link(CreateType.Source, node1, node2, new Range(0, 1));
ObjectWriter objectWriter = MAPPER.writerWithDefaultPrettyPrinter();
String s = objectWriter.writeValueAsString(link);
logger.debug(s);
}
use of com.fasterxml.jackson.databind.ObjectWriter in project pinpoint by naver.
the class PluginDisableIT method test.
@Test
public void test() throws Exception {
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "jackson");
mapper.writeValueAsString(map);
mapper.writeValueAsBytes(map);
ObjectWriter writer = mapper.writer();
writer.writeValueAsString(map);
writer.writeValueAsBytes(map);
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTraceCount(0);
}
use of com.fasterxml.jackson.databind.ObjectWriter in project spring-framework by spring-projects.
the class Jackson2JsonEncoder method encodeValue.
private DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, ResolvableType type, Map<String, Object> hints) {
TypeFactory typeFactory = this.mapper.getTypeFactory();
JavaType javaType = typeFactory.constructType(type.getType());
if (type.isInstance(value)) {
javaType = getJavaType(type.getType(), null);
}
ObjectWriter writer;
Class<?> jsonView = (Class<?>) hints.get(AbstractJackson2Codec.JSON_VIEW_HINT);
if (jsonView != null) {
writer = this.mapper.writerWithView(jsonView);
} else {
writer = this.mapper.writer();
}
if (javaType != null && javaType.isContainerType()) {
writer = writer.forType(javaType);
}
Boolean sse = (Boolean) hints.get(ServerSentEventHttpMessageWriter.SSE_CONTENT_HINT);
SerializationConfig config = writer.getConfig();
if (Boolean.TRUE.equals(sse) && config.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
writer = writer.with(this.ssePrettyPrinter);
}
DataBuffer buffer = bufferFactory.allocateBuffer();
OutputStream outputStream = buffer.asOutputStream();
try {
writer.writeValue(outputStream, value);
} catch (IOException ex) {
throw new CodecException("Error while writing the data", ex);
}
return buffer;
}
use of com.fasterxml.jackson.databind.ObjectWriter in project retrofit by square.
the class JacksonConverterFactory method requestBodyConverter.
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectWriter writer = mapper.writerFor(javaType);
return new JacksonRequestBodyConverter<>(writer);
}
use of com.fasterxml.jackson.databind.ObjectWriter in project jackson-databind by FasterXML.
the class TestJDKSerialization method testEnumHandlers.
// for [databind#899]
public void testEnumHandlers() throws IOException {
ObjectMapper mapper = new ObjectMapper();
// ensure we have serializers and/or deserializers, first
String json = mapper.writerFor(EnumPOJO.class).writeValueAsString(new EnumPOJO());
EnumPOJO result = mapper.readerFor(EnumPOJO.class).readValue(json);
assertNotNull(result);
// and then use JDK serialization to freeze/thaw objects
byte[] bytes = jdkSerialize(mapper);
ObjectMapper mapper2 = jdkDeserialize(bytes);
assertNotNull(mapper2);
bytes = jdkSerialize(mapper.readerFor(EnumPOJO.class));
ObjectReader r = jdkDeserialize(bytes);
assertNotNull(r);
/* 14-Aug-2015, tatu: Looks like pre-loading JsonSerializer is problematic
* at this point; comment out for now. Try to fix later on.
*/
bytes = jdkSerialize(mapper.writerFor(EnumPOJO.class));
ObjectWriter w = jdkDeserialize(bytes);
assertNotNull(w);
// plus, ensure objects are usable:
String json2 = w.writeValueAsString(new EnumPOJO());
assertEquals(json, json2);
EnumPOJO result2 = r.readValue(json2);
assertNotNull(result2);
}
Aggregations