JacksonTester
AssertJ based JSON tester backed by Jackson. Usually instantiated via initFields, 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");
}
}
Content copied to clipboard
Author
Phillip Webb
Madhura Bhave
Diego Berrueta
Since
1.4.0
Parameters
<T>
the type under test
Constructors
Link copied to clipboard
Create a new JacksonTester instance.
constructor(resourceLoadClass: Class<out Any>, type: ResolvableType, objectMapper: ObjectMapper, view: Class<out Any>)
Functions
Link copied to clipboard
Returns a new instance of JacksonTester with the view that should be used for json serialization/deserialization.
Link copied to clipboard
Utility method to initialize JacksonTester fields.
Link copied to clipboard
Return ObjectContent from parsing the specific JSON bytes.
Return ObjectContent from parsing the specific JSON String.
Link copied to clipboard
Return the object created from parsing the specific JSON bytes.
Return the object created from parsing the specific JSON String.
Link copied to clipboard
Return ObjectContent from reading from the specified file.
Return ObjectContent from reading from the specified input stream.
Return ObjectContent from reading from the specified reader.
Return ObjectContent from reading from the specified classpath resource.
Return ObjectContent from reading from the specified resource.
Link copied to clipboard
Return the object created from reading from the specified file.
Return the object created from reading from the specified input stream.
Return the object created from reading from the specified reader.
Return the object created from reading from the specified classpath resource.
Return the object created from reading from the specified resource.
Link copied to clipboard
Return JsonContent from writing the specific value.