use of com.fasterxml.jackson.databind.ObjectReader in project Fast-Android-Networking by amitshekhariitbhu.
the class JacksonParserFactory method getObject.
@Override
public Object getObject(String string, Type type) {
try {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectReader objectReader = mapper.readerFor(javaType);
return objectReader.readValue(string);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.fasterxml.jackson.databind.ObjectReader in project pinpoint by naver.
the class ObjectMapperIT method testReadValue.
@Test
public void testReadValue() throws Exception {
String json_str = "{\"name\" : \"Jackson\"}";
byte[] json_b = json_str.getBytes("UTF-8");
mapper.readValue(json_str, __POJO.class);
mapper.readValue(json_b, __POJO.class);
ObjectReader reader = mapper.reader(__POJO.class);
reader.readValue(json_str);
reader.readValue(json_b);
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
Method mapperReadValueString = ObjectMapper.class.getMethod("readValue", String.class, Class.class);
Method mapperReadValueBytes = ObjectMapper.class.getMethod("readValue", byte[].class, Class.class);
Method readerReadValueString = ObjectReader.class.getMethod("readValue", String.class);
Method readerReadValueBytes = ObjectReader.class.getMethod("readValue", byte[].class);
verifier.verifyTrace(event(SERVICE_TYPE, mapperReadValueString, annotation(ANNOTATION_KEY, json_str.length())));
verifier.verifyTrace(event(SERVICE_TYPE, mapperReadValueBytes, annotation(ANNOTATION_KEY, json_b.length)));
verifier.verifyTrace(event(SERVICE_TYPE, readerReadValueString, annotation(ANNOTATION_KEY, json_str.length())));
verifier.verifyTrace(event(SERVICE_TYPE, readerReadValueBytes, annotation(ANNOTATION_KEY, json_b.length)));
verifier.verifyTraceCount(0);
}
use of com.fasterxml.jackson.databind.ObjectReader in project spring-framework by spring-projects.
the class Jackson2JsonDecoder method decodeInternal.
private Flux<Object> decodeInternal(JsonObjectDecoder objectDecoder, Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
Assert.notNull(inputStream, "'inputStream' must not be null");
Assert.notNull(elementType, "'elementType' must not be null");
MethodParameter methodParam = (elementType.getSource() instanceof MethodParameter ? (MethodParameter) elementType.getSource() : null);
Class<?> contextClass = (methodParam != null ? methodParam.getContainingClass() : null);
JavaType javaType = getJavaType(elementType.getType(), contextClass);
ObjectReader reader;
Class<?> jsonView = (Class<?>) hints.get(AbstractJackson2Codec.JSON_VIEW_HINT);
if (jsonView != null) {
reader = this.mapper.readerWithView(jsonView).forType(javaType);
} else {
reader = this.mapper.readerFor(javaType);
}
return objectDecoder.decode(inputStream, elementType, mimeType, hints).map(dataBuffer -> {
try {
Object value = reader.readValue(dataBuffer.asInputStream());
DataBufferUtils.release(dataBuffer);
return value;
} catch (IOException ex) {
throw new CodecException("Error while reading the data", ex);
}
});
}
use of com.fasterxml.jackson.databind.ObjectReader in project retrofit by square.
the class JacksonConverterFactory method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectReader reader = mapper.readerFor(javaType);
return new JacksonResponseBodyConverter<>(reader);
}
use of com.fasterxml.jackson.databind.ObjectReader in project jackson-databind by FasterXML.
the class EnumAltIdTest method testFailWhenCaseSensitiveAndToStringIsUpperCase.
public void testFailWhenCaseSensitiveAndToStringIsUpperCase() throws IOException {
ObjectReader r = READER_DEFAULT.forType(LowerCaseEnum.class).with(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
try {
r.readValue("\"A\"");
fail("InvalidFormatException expected");
} catch (InvalidFormatException e) {
verifyException(e, "value not one of declared Enum instance names: [a, b, c]");
}
}
Aggregations