java.lang.Object
io.ebean.test.Json
Helper to convert to and from json using Jackson object mapper and
perform some useful asserts based on json content.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFor reading resource json content into a bean, list or jsonNode in a fluid style. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertContains(com.fasterxml.jackson.databind.JsonNode actualJsonNode, com.fasterxml.jackson.databind.JsonNode expectedJsonNode) Assert all the fields in the expectedJson are present in actualJson and values match.static voidassertContains(String actualJson, String expectedJson) Assert all the fields in the expectedJson are present in actualJson and values match.static <T> TReturn a typed object from json content.static <T> TreadFromResource(Class<T> type, String resourcePath) Return a bean from json content of a resource path.static <T> List<T> Return a list of a given type from json content.static com.fasterxml.jackson.databind.JsonNodeParse json into a generic JsonNode structure.static com.fasterxml.jackson.databind.JsonNodereadNodeFromResource(String resourcePath) Parse json into a generic JsonNode structure from resource.static StringreadResource(String resourcePath) Read the content for the given resource path.static Json.ResourceFor fluid style reading resource json content and return as a bean, list of bean or JsonNode.static StringtoJsonString(Object bean) Serialize object to string
-
Constructor Details
-
Json
public Json()
-
-
Method Details
-
resource
For fluid style reading resource json content and return as a bean, list of bean or JsonNode.PlainBean bean = Json.resource("/example/plain-list.json").asBean(PlainBean.class); List<PlainBean> list = Json.resource("/example/plain-list.json").asList(PlainBean.class); JsonNode jsonNode = Json.resource("/example/plain-list.json").asJsonNode();- Parameters:
resourcePath- The resource path where the json content is read from- Returns:
- The resource to convert to a bean or jsonNode etc
-
assertContains
Assert all the fields in the expectedJson are present in actualJson and values match. -
assertContains
public static void assertContains(com.fasterxml.jackson.databind.JsonNode actualJsonNode, com.fasterxml.jackson.databind.JsonNode expectedJsonNode) Assert all the fields in the expectedJson are present in actualJson and values match. -
readResource
Read the content for the given resource path. -
readFromResource
Return a bean from json content of a resource path. -
read
Return a typed object from json content. -
readList
Return a list of a given type from json content. -
readNodeFromResource
Parse json into a generic JsonNode structure from resource. -
readNode
Parse json into a generic JsonNode structure. -
toJsonString
Serialize object to string
-