Search in sources :

Example 1 with ContextAttributes

use of com.fasterxml.jackson.databind.cfg.ContextAttributes in project jackson-databind by FasterXML.

the class ObjectReaderTest method testMiscSettings.

public void testMiscSettings() throws Exception {
    ObjectReader r = MAPPER.reader();
    assertSame(MAPPER.getFactory(), r.getFactory());
    JsonFactory f = new JsonFactory();
    r = r.with(f);
    assertSame(f, r.getFactory());
    assertSame(r, r.with(f));
    assertNotNull(r.getTypeFactory());
    assertNull(r.getInjectableValues());
    r = r.withAttributes(Collections.emptyMap());
    ContextAttributes attrs = r.getAttributes();
    assertNotNull(attrs);
    assertNull(attrs.getAttribute("abc"));
    assertSame(r, r.withoutAttribute("foo"));
    ObjectReader newR = r.forType(MAPPER.constructType(String.class));
    assertNotSame(r, newR);
    assertSame(newR, newR.forType(String.class));
    DeserializationProblemHandler probH = new DeserializationProblemHandler() {
    };
    newR = r.withHandler(probH);
    assertNotSame(r, newR);
    assertSame(newR, newR.withHandler(probH));
    r = newR;
}
Also used : DeserializationProblemHandler(com.fasterxml.jackson.databind.deser.DeserializationProblemHandler) ContextAttributes(com.fasterxml.jackson.databind.cfg.ContextAttributes)

Example 2 with ContextAttributes

use of com.fasterxml.jackson.databind.cfg.ContextAttributes in project jackson-databind by FasterXML.

the class TestObjectIdDeserialization method testCustomPoolResolver.

/*
    /*****************************************************
    /* Unit tests, custom id resolver
    /*****************************************************
     */
public void testCustomPoolResolver() throws Exception {
    Map<Object, WithCustomResolution> pool = new HashMap<Object, WithCustomResolution>();
    pool.put(1, new WithCustomResolution(1, 1));
    pool.put(2, new WithCustomResolution(2, 2));
    pool.put(3, new WithCustomResolution(3, 3));
    pool.put(4, new WithCustomResolution(4, 4));
    pool.put(5, new WithCustomResolution(5, 5));
    ContextAttributes attrs = MAPPER.getDeserializationConfig().getAttributes().withSharedAttribute(POOL_KEY, pool);
    String content = "{\"data\":[1,2,3,4,5]}";
    CustomResolutionWrapper wrapper = MAPPER.readerFor(CustomResolutionWrapper.class).with(attrs).readValue(content);
    assertFalse(wrapper.data.isEmpty());
    for (WithCustomResolution ob : wrapper.data) {
        assertSame(pool.get(ob.id), ob);
    }
}
Also used : ContextAttributes(com.fasterxml.jackson.databind.cfg.ContextAttributes) HashMap(java.util.HashMap)

Aggregations

ContextAttributes (com.fasterxml.jackson.databind.cfg.ContextAttributes)2 DeserializationProblemHandler (com.fasterxml.jackson.databind.deser.DeserializationProblemHandler)1 HashMap (java.util.HashMap)1