Package com.clumd.projects.javajson.api
Interface JsonBuilder
- All Superinterfaces:
JsonGenerator
- All Known Implementing Classes:
BasicJsonBuilder
public interface JsonBuilder extends JsonGenerator
Defines the required methods to build a JSON object from Java in this framework.
The minimum wrapper for the output is an Object.
You cannot return an array, or any primitive JSON datatype without first wrapping them in an object.
For each add method, If any element of the key does not already exist it will be created along the way. Additionally, when adding to an object, if your key has spaces, you can use ['spaced key'] notation for this. When adding to an array, you should leave the array accessor anonymous, e.g. someArray[] However, if you are adding to an existing element of an array, you should address the index. e.g. someArray[2]
-
Method Summary
Modifier and Type Method Description JsonBuilderaddBoolean(String path, boolean value)Add a boolean to this JSON object.JsonBuilderaddBuilderBlock(String path, Json value)Use an existing, compiled piece of JSON, converted to a JsonBuilder, then assigned to the value at the path.JsonBuilderaddBuilderBlock(String path, JsonBuilder value)Add another JsonBuilder (representing an object) with partially filled values to this JSON object.JsonBuilderaddDouble(String path, double value)Add a double to this JSON object.JsonBuilderaddLong(String path, long value)Add a long to this JSON object.JsonBuilderaddString(String path, String value)Add a string to this JSON object.Jsonbuild()Used to finalise the current builder into a fully compiled Java-JSON object.JsonBuilderbuilder()Used to create an empty JSON shell.JsonBuilderconvertFromJSON(Json json)Break a full JSON object down into a builder representation of itself to be added to.
-
Method Details
-
builder
JsonBuilder builder()Used to create an empty JSON shell.- Returns:
- An empty JSON builder, which will default to an object.
-
addBoolean
Add a boolean to this JSON object.- Parameters:
path- The JSON path/key to place the object at.value- The boolean value to set at the given key.- Returns:
- The current JSON object, with the new value assigned.
- Throws:
BuildException- Thrown if the key was malformed or conflicts with values already present along it's path
-
addLong
Add a long to this JSON object.- Parameters:
path- The JSON path/key to place the object at.value- The long value to set at the given key.- Returns:
- The current JSON object, with the new value assigned.
- Throws:
BuildException- Thrown if the key was malformed or conflicts with values already present along it's path
-
addDouble
Add a double to this JSON object.- Parameters:
path- The JSON path/key to place the object at.value- The double value to set at the given key.- Returns:
- The current JSON object, with the new value assigned.
- Throws:
BuildException- Thrown if the key was malformed or conflicts with values already present along it's path
-
addString
Add a string to this JSON object.- Parameters:
path- The JSON path/key to place the object at.value- The string value to set at the given key.- Returns:
- The current JSON object, with the new value assigned.
- Throws:
BuildException- Thrown if the key was malformed or conflicts with values already present along it's path
-
addBuilderBlock
Add another JsonBuilder (representing an object) with partially filled values to this JSON object.- Parameters:
path- The JSON path/key to place the object at.value- The JsonBuilder value to set at the given key.- Returns:
- The current JSON object, with the new value assigned.
- Throws:
BuildException- Thrown if the key was malformed or conflicts with values already present along it's path
-
addBuilderBlock
Use an existing, compiled piece of JSON, converted to a JsonBuilder, then assigned to the value at the path.- Parameters:
path- The JSON path/key to place the object at.value- The JSON value to set at the given key.- Returns:
- The current JSON object, with the new value assigned.
- Throws:
BuildException- Thrown if the key was malformed or conflicts with values already present along it's path
-
convertFromJSON
Break a full JSON object down into a builder representation of itself to be added to.- Parameters:
json- The JSON object to break into a builder representation.- Returns:
- The given JSON object, as a JsonBuilder.
-
build
Json build()Used to finalise the current builder into a fully compiled Java-JSON object.- Returns:
- The compiled JSON object with all values set through this builder.
-