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 and Type | Class and Description |
|---|---|
class |
JsonFluentAssert.ArrayAssert
Array assertions
|
| Modifier | Constructor and Description |
|---|---|
protected |
JsonFluentAssert(Object actual) |
protected |
JsonFluentAssert(Object actual,
String path,
String description,
Configuration configuration) |
| 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.ArrayAssert |
isArray()
Fails if the selected JSON is not an Array or is not present.
|
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.
|
void |
isString()
Fails if the selected JSON is not a String or is not present.
|
void |
isStringEqualTo(String expected)
Fails if the selected JSON is not a String or is not present or the value
is not equal to expected value.
|
JsonFluentAssert |
node(String path)
Creates an assert object that only compares given node.
|
JsonFluentAssert |
treatingNullAsAbsent()
Deprecated.
Use when(Option.TREATING_NULL_AS_ABSENT)
|
JsonFluentAssert |
when(Option firstOption,
Option... otherOptions)
Sets options changing comparison behavior.
|
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, Configuration configuration)
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)
isStringEqualTo(String).
If the string parameter is not a valid JSON, it is quoted automatically.expected - this object.isStringEqualTo(String)public void isStringEqualTo(String expected)
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 - @Deprecated public JsonFluentAssert treatingNullAsAbsent()
public JsonFluentAssert when(Option firstOption, Option... otherOptions)
OptionfirstOption - otherOptions - Optionpublic JsonFluentAssert isAbsent()
public JsonFluentAssert isPresent()
public JsonFluentAssert.ArrayAssert isArray()
public void isString()
Copyright © 2015. All Rights Reserved.