- java.lang.Object
-
- io.ebean.test.Json
-
public class Json extends Object
Helper to convert to and from json using Jackson object mapper and perform some useful asserts based on json content.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJson.ResourceFor reading resource json content into a bean, list or jsonNode in a fluid style.
-
Constructor Summary
Constructors Constructor Description Json()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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> Tread(Class<T> type, String json)Return 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>readList(Class<T> type, String json)Return a list of a given type from json content.static com.fasterxml.jackson.databind.JsonNodereadNode(String json)Parse 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.Resourceresource(String resourcePath)For fluid style reading resource json content and return as a bean, list of bean or JsonNode.static StringtoJsonString(Object bean)Serialize object to string
-
-
-
Method Detail
-
resource
public static Json.Resource resource(String resourcePath)
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
public static void assertContains(String actualJson, String expectedJson)
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
public static String readResource(String resourcePath)
Read the content for the given resource path.
-
readFromResource
public static <T> T readFromResource(Class<T> type, String resourcePath)
Return a bean from json content of a resource path.
-
readList
public static <T> List<T> readList(Class<T> type, String json)
Return a list of a given type from json content.
-
readNodeFromResource
public static com.fasterxml.jackson.databind.JsonNode readNodeFromResource(String resourcePath)
Parse json into a generic JsonNode structure from resource.
-
readNode
public static com.fasterxml.jackson.databind.JsonNode readNode(String json)
Parse json into a generic JsonNode structure.
-
-