Package utils

Class JsonUtils

java.lang.Object
utils.JsonUtils

public class JsonUtils extends Object
Utility class for JSON serialization and deserialization.
  • Constructor Details

    • JsonUtils

      public JsonUtils()
  • Method Details

    • JsonStringify

      public static <T> String JsonStringify(T object)
      Serializes a Java object to its JSON string representation.
      Type Parameters:
      T - the type of the object
      Parameters:
      object - the object to serialize
      Returns:
      the JSON string, or null if serialization fails
    • mapToJson

      public static String mapToJson(Map<String,Object> map)
      Converts a Map to a JSON string.
      Parameters:
      map - the Map
      Returns:
      a JSOn String representation of the Map, or an empty string if conversion fails
    • jsonFileToMap

      public static Map<String,Object> jsonFileToMap(String filename)
      Converts a JSON file from the classpath to a Map.
      Parameters:
      filename - the name of the JSON file in the classpath
      Returns:
      a Map representation of the JSON, or an empty map if conversion fails
    • fromJson

      public static <T> T fromJson(String filename, Class<T> clazz, boolean isFile)
      Reads and converts a JSON file from the classpath to an object of the specified class.
      Type Parameters:
      T - the type of object to convert to
      Parameters:
      filename - the name of the JSON file in the classpath
      clazz - the class of the target object
      isFile - whether the input is a file (unused parameter)
      Returns:
      an instance of the target class, or null if the file is not found or conversion fails