Class Jackson2Tester<T>
java.lang.Object
org.springframework.boot.test.json.AbstractJsonMarshalTester<T>
org.springframework.boot.test.json.Jackson2Tester<T>
- Type Parameters:
T- the type under test
@Deprecated(since="4.0.0",
forRemoval=true)
public class Jackson2Tester<T>
extends AbstractJsonMarshalTester<T>
Deprecated, for removal: This API element is subject to removal in a future version.
since 4.0.0 for removal in 4.2.0 in favor of Jackson 3.
AssertJ based JSON tester backed by Jackson 2. Usually instantiated via
initFields(Object, ObjectMapper), for example:
public class ExampleObjectJsonTests {
private Jackson2Tester<ExampleObject> json;
@Before
public void setup() {
ObjectMapper objectMapper = new ObjectMapper();
Jackson2Tester.initFields(this, objectMapper);
}
@Test
public void testWriteJson() throws IOException {
ExampleObject object = //...
assertThat(json.write(object)).isEqualToJson("expected.json");
}
}
See AbstractJsonMarshalTester for more details.- Since:
- 4.0.0
- Author:
- Phillip Webb, Madhura Bhave, Diego Berrueta
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractJsonMarshalTester
AbstractJsonMarshalTester.FieldInitializer<M> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJackson2Tester(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Deprecated, for removal: This API element is subject to removal in a future version.Create a newJackson2Testerinstance.Jackson2Tester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Deprecated, for removal: This API element is subject to removal in a future version.Create a newJackson2Testerinstance.Jackson2Tester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper, @Nullable Class<?> view) Deprecated, for removal: This API element is subject to removal in a future version.Create a newJackson2Testerinstance. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated, for removal: This API element is subject to removal in a future version.Returns a new instance ofJackson2Testerwith the view that should be used for json serialization/deserialization.protected JsonContent<T> getJsonContent(String json) Deprecated, for removal: This API element is subject to removal in a future version.Factory method used to get aJsonContentinstance from a source JSON string.static voidinitFields(Object testInstance, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Deprecated, for removal: This API element is subject to removal in a future version.Utility method to initializeJackson2Testerfields.static voidinitFields(Object testInstance, ObjectFactory<com.fasterxml.jackson.databind.ObjectMapper> objectMapperFactory) Deprecated, for removal: This API element is subject to removal in a future version.Utility method to initializeJackson2Testerfields.protected TreadObject(InputStream inputStream, ResolvableType type) Deprecated, for removal: This API element is subject to removal in a future version.Read from the specified input stream to create an object of the specified type.protected TreadObject(Reader reader, ResolvableType type) Deprecated, for removal: This API element is subject to removal in a future version.Read from the specified reader to create an object of the specified type.protected StringwriteObject(T value, ResolvableType type) Deprecated, for removal: This API element is subject to removal in a future version.Write the specified object to a JSON string.Methods inherited from class AbstractJsonMarshalTester
getResourceLoadClass, getType, initialize, parse, parse, parseObject, parseObject, read, read, read, read, read, readObject, readObject, readObject, readObject, readObject, write
-
Constructor Details
-
Jackson2Tester
protected Jackson2Tester(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Deprecated, for removal: This API element is subject to removal in a future version.Create a newJackson2Testerinstance.- Parameters:
objectMapper- the Jackson object mapper
-
Jackson2Tester
public Jackson2Tester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Deprecated, for removal: This API element is subject to removal in a future version.Create a newJackson2Testerinstance.- Parameters:
resourceLoadClass- the source class used to load resourcestype- the type under testobjectMapper- the Jackson object mapper
-
Jackson2Tester
public Jackson2Tester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper, @Nullable Class<?> view) Deprecated, for removal: This API element is subject to removal in a future version.Create a newJackson2Testerinstance.- Parameters:
resourceLoadClass- the source class used to load resourcestype- the type under testobjectMapper- the Jackson object mapperview- the JSON view
-
-
Method Details
-
getJsonContent
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from class:AbstractJsonMarshalTesterFactory method used to get aJsonContentinstance from a source JSON string.- Overrides:
getJsonContentin classAbstractJsonMarshalTester<T>- Parameters:
json- the source JSON- Returns:
- a new
JsonContentinstance
-
readObject
Deprecated, for removal: This API element is subject to removal in a future version.Description 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 classAbstractJsonMarshalTester<T>- Parameters:
inputStream- the source input stream (nevernull)type- the resulting type (nevernull)- Returns:
- the resulting object
- Throws:
IOException- on read error
-
readObject
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from class:AbstractJsonMarshalTesterRead from the specified reader to create an object of the specified type.- Specified by:
readObjectin classAbstractJsonMarshalTester<T>- Parameters:
reader- the source reader (nevernull)type- the resulting type (nevernull)- Returns:
- the resulting object
- Throws:
IOException- on read error
-
writeObject
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from class:AbstractJsonMarshalTesterWrite the specified object to a JSON string.- Specified by:
writeObjectin classAbstractJsonMarshalTester<T>- Parameters:
value- the source value (nevernull)type- the resulting type (nevernull)- Returns:
- the JSON string
- Throws:
IOException- on write error
-
initFields
public static void initFields(Object testInstance, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Deprecated, for removal: This API element is subject to removal in a future version.Utility method to initializeJackson2Testerfields. Seeclass-level documentationfor example usage.- Parameters:
testInstance- the test instanceobjectMapper- the JSON mapper- See Also:
-
initFields
public static void initFields(Object testInstance, ObjectFactory<com.fasterxml.jackson.databind.ObjectMapper> objectMapperFactory) Deprecated, for removal: This API element is subject to removal in a future version.Utility method to initializeJackson2Testerfields. Seeclass-level documentationfor example usage.- Parameters:
testInstance- the test instanceobjectMapperFactory- a factory to create the object mapper- See Also:
-
forView
Deprecated, for removal: This API element is subject to removal in a future version.Returns a new instance ofJackson2Testerwith the view that should be used for json serialization/deserialization.- Parameters:
view- the view class- Returns:
- the new instance
-