Search in sources :

Example 21 with ObjectReader

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;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 22 with ObjectReader

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);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 23 with ObjectReader

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);
        }
    });
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) CodecException(org.springframework.core.codec.CodecException) IOException(java.io.IOException) MethodParameter(org.springframework.core.MethodParameter)

Example 24 with ObjectReader

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);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 25 with ObjectReader

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]");
    }
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) InvalidFormatException(com.fasterxml.jackson.databind.exc.InvalidFormatException)

Aggregations

ObjectReader (com.fasterxml.jackson.databind.ObjectReader)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 Test (org.junit.Test)12 IOException (java.io.IOException)6 JavaType (com.fasterxml.jackson.databind.JavaType)5 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)4 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 Method (java.lang.reflect.Method)2 NoSuchElementException (java.util.NoSuchElementException)2 AclEntry (org.apache.hadoop.fs.permission.AclEntry)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 InvalidFormatException (com.fasterxml.jackson.databind.exc.InvalidFormatException)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)1 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)1 AvroFactory (com.fasterxml.jackson.dataformat.avro.AvroFactory)1 AvroSchema (com.fasterxml.jackson.dataformat.avro.AvroSchema)1