Class JsonBuilder


  • @Deprecated
    public class JsonBuilder
    extends Object
    Deprecated.
    Provide a JSON (JavaScript Object Notation) string builder class which can be used to convert Java objects into JSON string for use in Dynamic Data Services.

    PLEASE NOTE: this class is deprecated - it is recommended that you use the included Gson library instead

    Dynamic Data Example

    The Dynamic Data Groovy example below performs a database query and then appends the query row list to a JsonBuilder as an array.
     // Provides form lookup form data service by calling a configurable Groovy script.
     //
     //   Script parameters include:
     //       form : com.avoka.fc.core.entity.Form
     //       request : javax.servlet.http.HttpServletRequest
     //       serviceDefinition : com.avoka.fc.core.entity.ServiceDefinition
     //       serviceParameters : Map
     //
     //   Script return:
     //       JSON string data value to be bound into the form data model
     //
     import groovy.sql.Sql
     import com.avoka.component.json.JsonBuilder
    
     def sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:XE", "txmanager", "password", "oracle.jdbc.driver.OracleDriver")
    
     def rowList = sql.rows("select db_version as \"Version\", release_version as \"Release\" from db_version_update")
    
     def jsonBuilder = new JsonBuilder()
    
     def jsonResult = jsonBuilder.appendArray(rowList).toString()
    
     sql.close()
    
     return jsonResult 
    The JsonBuilder will convert this row data into a valid JSON array text, which will have the format:
     [{"Version": 1025, "Release": "3.5.1"},{"Version": 1026, "Release": "3.5.1"},{"Version": 1027, "Release": "3.5.1"}] 
    This data can then be returned to a Composer form which can display the data as a grid.

    References

    Since:
    3.5.1
    • Constructor Detail

      • JsonBuilder

        public JsonBuilder()
        Deprecated.
    • Method Detail

      • openArray

        public JsonBuilder openArray()
        Deprecated.
        Open a JSON array by appending the '[' character.
        Returns:
        this JsonBuilder instance
      • openObject

        public JsonBuilder openObject()
        Deprecated.
        Open a JSON object by appending the '{' character.
        Returns:
        this JsonBuilder instance
        Since:
        4.1.0
      • closeArray

        public JsonBuilder closeArray()
        Deprecated.
        Close a JSON array by appending the ']' character.
        Returns:
        this JsonBuilder instance
      • closeObject

        public JsonBuilder closeObject()
        Deprecated.
        Close a JSON object by appending the '}' character.
        Returns:
        this JsonBuilder instance
        Since:
        4.1.0
      • append

        public JsonBuilder append​(String name,
                                  Object value)
        Deprecated.
        Append the given name and value to the JSON string builder.
        Parameters:
        name - the JSON name to append
        value - the JSON value to append
        Returns:
        this JsonBuilder instance
      • append

        public JsonBuilder append​(Object object)
        Deprecated.
        Append the given object to the JSON string builder.
        Parameters:
        object - the Java object to append
        Returns:
        this JsonBuilder instance
      • appendArray

        public JsonBuilder appendArray​(Collection collection)
        Deprecated.
        Append the given collection to the JSON string builder as JSON array.
        Parameters:
        collection - the collection object to append
        Returns:
        this JsonBuilder instance
      • appendResultSet

        public JsonBuilder appendResultSet​(ResultSet resultSet)
        Deprecated.
        Append the given ResultSet to the JSON string builder as JSON array.
        Parameters:
        resultSet - the result set to append
        Returns:
        this JsonBuilder instance
      • appendResultSetRow

        public JsonBuilder appendResultSetRow​(ResultSet resultSet)
        Deprecated.
        Append a single row from the given ResultSet to the JSON string builder as JSON array.
        Parameters:
        resultSet - the result set row to append
        Returns:
        this JsonBuilder instance
      • isEmpty

        public boolean isEmpty()
        Deprecated.
        Return true if the JSON string is empty.
        Returns:
        true if the JSON string is empty
      • toString

        public String toString()
        Deprecated.
        Return the JSON string value.
        Overrides:
        toString in class Object
        Returns:
        the JSON string value