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;
}
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);
}
}
Aggregations