Search in sources :

Example 1 with Deserializer

use of org.springframework.boot.jackson.NameAndAgeJsonComponent.Deserializer 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);
}
Also used : Deserializer(org.springframework.boot.jackson.NameAndAgeJsonComponent.Deserializer) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 Test (org.junit.Test)1 Deserializer (org.springframework.boot.jackson.NameAndAgeJsonComponent.Deserializer)1