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,
BigDecimal numericComparisonTolerance,
boolean treatNullAsAbsent) |
| 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 |
isAbsent()
Fails if the node exists.
|
JsonFluentAssert |
isEqualTo(Object expected)
Compares JSON for equality.
|
JsonFluentAssert |
isNotEqualTo(Object expected)
Fails if compared documents are equal.
|
JsonFluentAssert |
isPresent()
Fails if the node is missing.
|
JsonFluentAssert |
node(String path)
Creates an assert object that only compares given node.
|
JsonFluentAssert |
treatingNullAsAbsent()
When set to true, treats null nodes in actual value as absent.
|
JsonFluentAssert |
withTolerance(BigDecimal tolerance)
Sets the tolerance for floating number comparison.
|
JsonFluentAssert |
withTolerance(double tolerance)
Sets the tolerance for floating number comparison.
|
protected JsonFluentAssert(Object actual, String path, String description, String ignorePlaceholder, BigDecimal numericComparisonTolerance, boolean treatNullAsAbsent)
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 - public JsonFluentAssert withTolerance(double tolerance)
tolerance - public JsonFluentAssert withTolerance(BigDecimal tolerance)
tolerance - public JsonFluentAssert treatingNullAsAbsent()
public JsonFluentAssert isAbsent()
public JsonFluentAssert isPresent()
Copyright © 2014. All Rights Reserved.