Search in sources :

Example 6 with ObjectReader

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

Example 7 with ObjectReader

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

Example 8 with ObjectReader

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

Example 9 with ObjectReader

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

Example 10 with ObjectReader

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);
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) StorelessUnivariateStatistic(org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)

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