Class JsonUtil

java.lang.Object
swiss.trustbroker.common.util.JsonUtil

public class JsonUtil extends Object
  • Method Details

    • parseJson

      public static Object parseJson(String jsonData, boolean tryOnly)
      Parameters:
      jsonData - JSON (may be null)
      tryOnly - if true returns null in case of errors
      Returns:
      Map of property -> value for JSON objects, List of values for JSON arrays, or String value of primitives
    • parseJsonObject

      public static Map<String,Object> parseJsonObject(String jsonData, boolean tryOnly)
      Parameters:
      jsonData - JSON (may be null)
      tryOnly - if true returns null in case of errors
      Returns:
      Map of property -> value containing List of values for JSON arrays, or String value of primitives
    • parseJsonArray

      public static List<Object> parseJsonArray(String jsonData, boolean tryOnly)
      Parameters:
      jsonData - JSON (may be null)
      tryOnly - if true returns null in case of errors
      Returns:
      List of values for JSON arrays, containing Map of property -> value, List, or String value of primitives
    • getField

      public static <T> T getField(Map<String,Object> jsonMap, String attribute, Class<T> expectedClass)
      Type Parameters:
      T -
      Parameters:
      jsonMap - returned by parseJsonObject
      attribute -
      expectedClass -
      Returns:
      attribute from map or null if not found or not of expectedClass
    • serializeToJson

      public static String serializeToJson(Object dto)
    • serializeToJson

      public static String serializeToJson(Object dto, tools.jackson.databind.ObjectMapper objectMapper)