Class JSONUtil

java.lang.Object
org.glassfish.admingui.common.util.JSONUtil

public class JSONUtil extends Object

This class provides basic JSON encoding / decoding. It has 2 primary methods that are of interest. The first allows you to encode a Java Object into JSON. The other allows you to create a Java data structure from a JSON String. See:

  • Constructor Details

    • JSONUtil

      public JSONUtil()
  • Method Details

    • jsonToJava

      public static Object jsonToJava(String json)

      This method returns a Java representation of the given JSON String. The Java data structure created will be created using Map's, String's, Long's, Float's, Boolean's, and List's as specified by the JSON String.

    • javaToJSON

      public static String javaToJSON(Object obj, int depth)

      This method attempts to convert the given Object into a JSON String to given depth. If -1 (or lower) is supplied for depth, it will walk upto a default depth of 10 levels of the given Object. If 0 is supplied, it will simply return "". 1 will encode the current Object, but no children. 2 will encode the given Object and its direct children (if any), and so on.

      Strings, Longs, Float, and primitives are considered to not have child Objects. Objects which have a public no-argument getXYZ() method are considered to be child Objects. Maps and Collections will be walked.