T
- the type under testpublic class JacksonTester<T> extends AbstractJsonMarshalTester<T>
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.AbstractJsonMarshalTester.FieldInitializer<M>
Modifier | Constructor and Description |
---|---|
|
JacksonTester(Class<?> resourceLoadClass,
ResolvableType type,
com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Create a new
JacksonTester instance. |
|
JacksonTester(Class<?> resourceLoadClass,
ResolvableType type,
com.fasterxml.jackson.databind.ObjectMapper objectMapper,
Class<?> view) |
protected |
JacksonTester(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Create a new
JacksonTester instance. |
Modifier and Type | Method and Description |
---|---|
JacksonTester<T> |
forView(Class<?> view)
Returns a new instance of
JacksonTester with the view that should be used
for json serialization/deserialization. |
protected JsonContent<T> |
getJsonContent(String json)
Factory method used to get a
JsonContent instance from a source JSON
string. |
static void |
initFields(Object testInstance,
ObjectFactory<com.fasterxml.jackson.databind.ObjectMapper> objectMapperFactory)
Utility method to initialize
JacksonTester fields. |
static void |
initFields(Object testInstance,
com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Utility method to initialize
JacksonTester fields. |
protected T |
readObject(InputStream inputStream,
ResolvableType type)
Read from the specified input stream to create an object of the specified type.
|
protected T |
readObject(Reader reader,
ResolvableType type)
Read from the specified reader to create an object of the specified type.
|
protected String |
writeObject(T value,
ResolvableType type)
Write the specified object to a JSON string.
|
getResourceLoadClass, getType, initialize, parse, parse, parseObject, parseObject, read, read, read, read, read, readObject, readObject, readObject, readObject, readObject, write
protected JacksonTester(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
JacksonTester
instance.objectMapper
- the Jackson object mapperpublic JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
JacksonTester
instance.resourceLoadClass
- the source class used to load resourcestype
- the type under testobjectMapper
- the Jackson object mapperpublic JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<?> view)
protected JsonContent<T> getJsonContent(String json)
AbstractJsonMarshalTester
JsonContent
instance from a source JSON
string.getJsonContent
in class AbstractJsonMarshalTester<T>
json
- the source JSONJsonContent
instanceprotected T readObject(InputStream inputStream, ResolvableType type) throws IOException
AbstractJsonMarshalTester
AbstractJsonMarshalTester.readObject(Reader, ResolvableType)
.readObject
in class AbstractJsonMarshalTester<T>
inputStream
- the source input stream (never null
)type
- the resulting type (never null
)IOException
- on read errorprotected T readObject(Reader reader, ResolvableType type) throws IOException
AbstractJsonMarshalTester
readObject
in class AbstractJsonMarshalTester<T>
reader
- the source reader (never null
)type
- the resulting type (never null
)IOException
- on read errorprotected String writeObject(T value, ResolvableType type) throws IOException
AbstractJsonMarshalTester
writeObject
in class AbstractJsonMarshalTester<T>
value
- the source value (never null
)type
- the resulting type (never null
)IOException
- on write errorpublic static void initFields(Object testInstance, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
JacksonTester
fields. See class-level documentation
for example usage.testInstance
- the test instanceobjectMapper
- the object mapperinitFields(Object, ObjectMapper)
public static void initFields(Object testInstance, ObjectFactory<com.fasterxml.jackson.databind.ObjectMapper> objectMapperFactory)
JacksonTester
fields. See class-level documentation
for example usage.testInstance
- the test instanceobjectMapperFactory
- a factory to create the object mapperinitFields(Object, ObjectMapper)
public JacksonTester<T> forView(Class<?> view)
JacksonTester
with the view that should be used
for json serialization/deserialization.view
- the view classCopyright © 2021 Pivotal Software, Inc.. All rights reserved.