Package com.avoka.component.json
Class JsonBuilder
java.lang.Object
com.avoka.component.json.JsonBuilder
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<String, String> // // 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 jsonResultThe
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Append the given object to the JSON string builder.Deprecated.Append the given name and value to the JSON string builder.appendArray
(Collection collection) Deprecated.Append the given collection to the JSON string builder as JSON array.appendResultSet
(ResultSet resultSet) Deprecated.Append the given ResultSet to the JSON string builder as JSON array.appendResultSetRow
(ResultSet resultSet) Deprecated.Append a single row from the given ResultSet to the JSON string builder as JSON array.Deprecated.Close a JSON array by appending the ']' character.Deprecated.Close a JSON object by appending the '}' character.boolean
isEmpty()
Deprecated.Return true if the JSON string is empty.Deprecated.Open a JSON array by appending the '[' character.Deprecated.Open a JSON object by appending the '{' character.toString()
Deprecated.Return the JSON string value.
-
Constructor Details
-
JsonBuilder
public JsonBuilder()Deprecated.
-
-
Method Details
-
openArray
Deprecated.Open a JSON array by appending the '[' character.- Returns:
- this JsonBuilder instance
-
openObject
Deprecated.Open a JSON object by appending the '{' character.- Returns:
- this JsonBuilder instance
- Since:
- 4.1.0
-
closeArray
Deprecated.Close a JSON array by appending the ']' character.- Returns:
- this JsonBuilder instance
-
closeObject
Deprecated.Close a JSON object by appending the '}' character.- Returns:
- this JsonBuilder instance
- Since:
- 4.1.0
-
append
Deprecated.Append the given name and value to the JSON string builder.- Parameters:
name
- the JSON name to appendvalue
- the JSON value to append- Returns:
- this JsonBuilder instance
-
append
Deprecated.Append the given object to the JSON string builder.- Parameters:
object
- the Java object to append- Returns:
- this JsonBuilder instance
-
appendArray
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
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
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
Deprecated.Return the JSON string value.
-