use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class AbstracTypeMapping1186Test method testDeserializeMyContainer.
public void testDeserializeMyContainer() throws Exception {
Module module = new SimpleModule().addAbstractTypeMapping(IContainer.class, MyContainer.class);
final ObjectMapper mapper = new ObjectMapper().registerModule(module);
String json = "{\"ts\": [ { \"msg\": \"hello\"} ] }";
final Object o = mapper.readValue(json, mapper.getTypeFactory().constructParametricType(IContainer.class, MyObject.class));
assertEquals(MyContainer.class, o.getClass());
MyContainer<?> myc = (MyContainer<?>) o;
assertEquals(1, myc.ts.size());
Object value = myc.ts.get(0);
assertEquals(MyObject.class, value.getClass());
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class TypeResolverTest method testSubtypeResolution.
public static void testSubtypeResolution() throws Exception {
ObjectMapper mapper = new ObjectMapper();
SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
resolver.addMapping(Map.class, MyMap.class);
SimpleModule basicModule = new SimpleModule();
basicModule.setAbstractTypes(resolver);
mapper.registerModule(basicModule);
String value = "{\"z\": {\"zz\": {\"a\": 42}}}";
A a = mapper.readValue(value, A.class);
Map map = a.getMap();
assertEquals(MyMap.class, map.getClass());
Object ob = map.get("zz");
assertEquals(B.class, ob.getClass());
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class TestMixinMerging method testDisappearingMixins515.
/*
/**********************************************************
/* Unit tests
/**********************************************************
*/
// for [Issue#515]
public void testDisappearingMixins515() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS).disable(MapperFeature.AUTO_DETECT_FIELDS).disable(MapperFeature.AUTO_DETECT_GETTERS).disable(MapperFeature.AUTO_DETECT_IS_GETTERS).disable(MapperFeature.INFER_PROPERTY_MUTATORS);
SimpleModule module = new SimpleModule("Test");
module.setMixInAnnotation(Person.class, PersonMixin.class);
mapper.registerModule(module);
assertEquals("{\"city\":\"Seattle\"}", mapper.writeValueAsString(new PersonImpl()));
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project retrofit by square.
the class JacksonConverterFactoryTest method setUp.
@Before
public void setUp() {
SimpleModule module = new SimpleModule();
module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY));
Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(JacksonConverterFactory.create(mapper)).build();
service = retrofit.create(Service.class);
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project spring-boot by spring-projects.
the class JsonObjectDeserializerTests method deserializeObjectShouldReadJson.
@Test
public void deserializeObjectShouldReadJson() throws Exception {
Deserializer deserializer = new NameAndAgeJsonComponent.Deserializer();
SimpleModule module = new SimpleModule();
module.addDeserializer(NameAndAge.class, deserializer);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
NameAndAge nameAndAge = mapper.readValue("{\"name\":\"spring\",\"age\":100}", NameAndAge.class);
assertThat(nameAndAge.getName()).isEqualTo("spring");
assertThat(nameAndAge.getAge()).isEqualTo(100);
}
Aggregations