use of com.fasterxml.jackson.databind.ObjectReader in project jackson-databind by FasterXML.
the class TestJDKSerialization method testObjectReader.
public void testObjectReader() throws IOException {
ObjectReader origReader = MAPPER.readerFor(MyPojo.class);
String JSON = "{\"x\":1,\"y\":2}";
MyPojo p1 = origReader.readValue(JSON);
assertEquals(2, p1.y);
ObjectReader anyReader = MAPPER.readerFor(AnyBean.class);
AnyBean any = anyReader.readValue(JSON);
assertEquals(Integer.valueOf(2), any.properties().get("y"));
byte[] readerBytes = jdkSerialize(origReader);
ObjectReader reader2 = jdkDeserialize(readerBytes);
MyPojo p2 = reader2.readValue(JSON);
assertEquals(2, p2.y);
ObjectReader anyReader2 = jdkDeserialize(jdkSerialize(anyReader));
AnyBean any2 = anyReader2.readValue(JSON);
assertEquals(Integer.valueOf(2), any2.properties().get("y"));
}
use of com.fasterxml.jackson.databind.ObjectReader in project jackson-databind by FasterXML.
the class EnumAltIdTest method testEnumDesIgnoringCaseWithUpperCaseToString.
public void testEnumDesIgnoringCaseWithUpperCaseToString() throws IOException {
ObjectReader r = MAPPER.readerFor(LowerCaseEnum.class).with(DeserializationFeature.READ_ENUMS_USING_TO_STRING, DeserializationFeature.READ_ENUMS_IGNORING_CASE);
assertEquals(LowerCaseEnum.A, r.readValue("\"A\""));
}
use of com.fasterxml.jackson.databind.ObjectReader in project jackson-databind by FasterXML.
the class EnumAltIdTest method testIgnoreCaseInEnumSet.
public void testIgnoreCaseInEnumSet() throws IOException {
ObjectReader r = READER_IGNORE_CASE.forType(new TypeReference<EnumSet<TestEnum>>() {
});
EnumSet<TestEnum> set = r.readValue("[\"jackson\"]");
assertEquals(1, set.size());
assertTrue(set.contains(TestEnum.JACKSON));
}
use of com.fasterxml.jackson.databind.ObjectReader in project jackson-databind by FasterXML.
the class TestPOJOAsArrayWithBuilder method testWithCreatorAndView.
public void testWithCreatorAndView() throws Exception {
ObjectReader reader = MAPPER.readerFor(CreatorValue.class);
CreatorValue value;
// First including values in view
value = reader.withView(String.class).readValue("[1,2,3]");
assertEquals(1, value.a);
assertEquals(2, value.b);
assertEquals(3, value.c);
// then not including view
value = reader.withView(Character.class).readValue("[1,2,3]");
assertEquals(1, value.a);
assertEquals(2, value.b);
assertEquals(0, value.c);
}
use of com.fasterxml.jackson.databind.ObjectReader in project uPortal by Jasig.
the class JpaStatisticalSummaryTest method testStorelessUnivariateStatistic.
public void testStorelessUnivariateStatistic(StorelessUnivariateStatistic sus, double expected) throws Exception {
assertEquals(expected, sus.getResult(), 0.1);
final ObjectMapper mapper = new ObjectMapper();
mapper.findAndRegisterModules();
//Configure Jackson to just use fields
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
mapper.addMixInAnnotations(Object.class, IgnoreTypeMixIn.class);
final FilterProvider filters = new SimpleFilterProvider().addFilter("storedDataFilter", SimpleBeanPropertyFilter.serializeAllExcept("storedData"));
final ObjectWriter ssWriter = mapper.writer(filters);
final ObjectReader ssReader = mapper.reader(sus.getClass());
final String susString = ssWriter.writeValueAsString(sus);
System.out.println(susString);
final StorelessUnivariateStatistic newSus = ssReader.readValue(susString);
assertEquals(expected, newSus.getResult(), 0.1);
}
Aggregations