public class JsonFluentAssert extends Object
assertThatJson("{\"test\":1}").isEqualTo("{\"test\":2}");
assertThatJson("{\"test\":1}").hasSameStructureAs("{\"test\":21}");
assertThatJson("{\"root\":{\"test\":1}}").node("root.test").isEqualTo("2");
Please note that the method name is assertThatJson and not assertThat. The reason is that we need to accept String parameter
and do not want to override standard FEST or AssertJ assertThat(String) method.
All the methods accept Objects as parameters. The supported types are:
Reader similarly to String| Modifier | Constructor and Description |
|---|---|
protected |
JsonFluentAssert(Object actual) |
protected |
JsonFluentAssert(Object actual,
String path,
String description,
String ignorePlaceholder) |
| Modifier and Type | Method and Description |
|---|---|
JsonFluentAssert |
as(String description)
Sets the description of this object.
|
static JsonFluentAssert |
assertThatJson(Object json)
Creates a new instance of
. |
JsonFluentAssert |
describedAs(String description)
Sets the description of this object.
|
JsonFluentAssert |
hasSameStructureAs(Object expected)
Compares JSON structure.
|
JsonFluentAssert |
ignoring(String ignorePlaceholder)
Sets the placeholder that can be used to ignore values.
|
JsonFluentAssert |
isEqualTo(Object expected)
Compares JSON for equality.
|
JsonFluentAssert |
isNotEqualTo(Object expected)
Fails if compared documents are equal.
|
JsonFluentAssert |
node(String path)
Creates an assert object that only compares given node.
|
protected JsonFluentAssert(Object actual, String path, String description, String ignorePlaceholder)
protected JsonFluentAssert(Object actual)
public static JsonFluentAssert assertThatJson(Object json)
JsonFluentAssert.
It is not called assertThat to not clash with StringAssert.
The json parameter is converted to JSON using ObjectMapper.json - public JsonFluentAssert isEqualTo(Object expected)
expected - this object.public JsonFluentAssert isNotEqualTo(Object expected)
expected - this object.public JsonFluentAssert hasSameStructureAs(Object expected)
expected - this object.public JsonFluentAssert node(String path)
assertThatJson("{\"root\":{\"test\":[1,2,3]}}").node("root.test[0]").isEqualTo("1");
path - public JsonFluentAssert as(String description)
description - public JsonFluentAssert describedAs(String description)
description - public JsonFluentAssert ignoring(String ignorePlaceholder)
ignorePlaceholder - Copyright © 2014. All Rights Reserved.