org.springframework.boot.test.json

Class JacksonTester<T>

  • Type Parameters:
    T - the type under test


    public class JacksonTester<T>
    extends AbstractJsonMarshalTester<T>
    AssertJ based JSON tester backed by Jackson. Usually instantiated via initFields(Object, ObjectMapper), for example:
     public class ExampleObjectJsonTests {
    
         private JacksonTester<ExampleObject> json;
    
         @Before
         public void setup() {
             ObjectMapper objectMapper = new ObjectMapper();
             JacksonTester.initFields(this, objectMapper);
         }
    
         @Test
         public void testWriteJson() throws IOException {
             ExampleObject object = //...
             assertThat(json.write(object)).isEqualToJson("expected.json");
         }
    
     }
     
    See AbstractJsonMarshalTester for more details.
    Since:
    1.4.0
    Author:
    Phillip Webb, Madhura Bhave