Package io.ebean.test

Class 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 class  Json.Resource
      For reading resource json content into a bean, list or jsonNode in a fluid style.
    • Constructor Summary

      Constructors 
      Constructor Description
      Json()  
    • Constructor Detail

      • Json

        public Json()
    • 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.
      • read

        public static <T> T read​(Class<T> type,
                                 String json)
        Return a typed object from json content.
      • 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.
      • toJsonString

        public static String toJsonString​(Object bean)
        Serialize object to string