Class JacksonTester<T>
java.lang.Object
org.springframework.boot.test.json.AbstractJsonMarshalTester<T>
org.springframework.boot.test.json.JacksonTester<T>
- Type Parameters:
- T- the type under test
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, Diego Berrueta
- 
Nested Class SummaryNested classes/interfaces inherited from class org.springframework.boot.test.json.AbstractJsonMarshalTesterAbstractJsonMarshalTester.FieldInitializer<M>
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedJacksonTester(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJacksonTesterinstance.JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJacksonTesterinstance.JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<?> view) 
- 
Method SummaryModifier and TypeMethodDescriptionReturns a new instance ofJacksonTesterwith the view that should be used for json serialization/deserialization.protected JsonContent<T>getJsonContent(String json) Factory method used to get aJsonContentinstance from a source JSON string.static voidinitFields(Object testInstance, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Utility method to initializeJacksonTesterfields.static voidinitFields(Object testInstance, ObjectFactory<com.fasterxml.jackson.databind.ObjectMapper> objectMapperFactory) Utility method to initializeJacksonTesterfields.protected TreadObject(InputStream inputStream, ResolvableType type) Read from the specified input stream to create an object of the specified type.protected TreadObject(Reader reader, ResolvableType type) Read from the specified reader to create an object of the specified type.protected StringwriteObject(T value, ResolvableType type) Write the specified object to a JSON string.Methods inherited from class org.springframework.boot.test.json.AbstractJsonMarshalTestergetResourceLoadClass, getType, initialize, parse, parse, parseObject, parseObject, read, read, read, read, read, readObject, readObject, readObject, readObject, readObject, write
- 
Constructor Details- 
JacksonTesterprotected JacksonTester(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJacksonTesterinstance.- Parameters:
- objectMapper- the Jackson object mapper
 
- 
JacksonTesterpublic JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJacksonTesterinstance.- Parameters:
- resourceLoadClass- the source class used to load resources
- type- the type under test
- objectMapper- the Jackson object mapper
 
- 
JacksonTesterpublic JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<?> view) 
 
- 
- 
Method Details- 
getJsonContentDescription copied from class:AbstractJsonMarshalTesterFactory method used to get aJsonContentinstance from a source JSON string.- Overrides:
- getJsonContentin class- AbstractJsonMarshalTester<T>
- Parameters:
- json- the source JSON
- Returns:
- a new JsonContentinstance
 
- 
readObjectDescription copied from class:AbstractJsonMarshalTesterRead from the specified input stream to create an object of the specified type. The default implementation delegates toAbstractJsonMarshalTester.readObject(Reader, ResolvableType).- Overrides:
- readObjectin class- AbstractJsonMarshalTester<T>
- Parameters:
- inputStream- the source input stream (never- null)
- type- the resulting type (never- null)
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
- 
readObjectDescription copied from class:AbstractJsonMarshalTesterRead from the specified reader to create an object of the specified type.- Specified by:
- readObjectin class- AbstractJsonMarshalTester<T>
- Parameters:
- reader- the source reader (never- null)
- type- the resulting type (never- null)
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
- 
writeObjectDescription copied from class:AbstractJsonMarshalTesterWrite the specified object to a JSON string.- Specified by:
- writeObjectin class- AbstractJsonMarshalTester<T>
- Parameters:
- value- the source value (never- null)
- type- the resulting type (never- null)
- Returns:
- the JSON string
- Throws:
- IOException- on write error
 
- 
initFieldspublic static void initFields(Object testInstance, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Utility method to initializeJacksonTesterfields. Seeclass-level documentationfor example usage.- Parameters:
- testInstance- the test instance
- objectMapper- the object mapper
- See Also:
 
- 
initFieldspublic static void initFields(Object testInstance, ObjectFactory<com.fasterxml.jackson.databind.ObjectMapper> objectMapperFactory) Utility method to initializeJacksonTesterfields. Seeclass-level documentationfor example usage.- Parameters:
- testInstance- the test instance
- objectMapperFactory- a factory to create the object mapper
- See Also:
 
- 
forViewReturns a new instance ofJacksonTesterwith the view that should be used for json serialization/deserialization.- Parameters:
- view- the view class
- Returns:
- the new instance
 
 
-