use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project jvm-serializers by eishay.
the class JacksonAvroDatabind method register.
public static void register(TestGroups groups) {
ObjectMapper mapper = new ObjectMapper(new AvroFactory());
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX);
JavaType type = mapper.constructType(MediaContent.class);
AvroSchema schema = new AvroSchema(Avro.Media.sMediaContent);
ObjectReader reader = mapper.readerFor(type).with(schema);
ObjectWriter writer = mapper.writerFor(type).with(schema);
groups.media.add(JavaBuiltIn.mediaTransformer, new StdJacksonDataBind<MediaContent>("avro/jackson/databind", type, mapper, reader, writer), new SerFeatures(SerFormat.JSON, SerGraph.FLAT_TREE, SerClass.ZERO_KNOWLEDGE, ""));
}
use of org.apache.flink.shaded.jackson2.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]");
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader 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);
}
use of org.apache.flink.shaded.jackson2.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 org.apache.flink.shaded.jackson2.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);
}
});
}
Aggregations