Class BasicJsonBuilder

java.lang.Object
com.clumd.projects.javajson.core.BasicJsonBuilder
All Implemented Interfaces:
JsonBuilder, JsonGenerator

public final class BasicJsonBuilder
extends Object
implements JsonBuilder, JsonGenerator
  • Constructor Details

  • Method Details

    • getBuilder

      public static BasicJsonBuilder getBuilder()
    • builder

      public BasicJsonBuilder builder()
      Description copied from interface: JsonBuilder
      Used to create an empty JSON shell.
      Specified by:
      builder in interface JsonBuilder
      Returns:
      An empty JSON builder, which will default to an object.
    • build

      public Json build() throws BuildException
      Description copied from interface: JsonBuilder
      Used to finalise the current builder into a fully compiled Java-JSON object.
      Specified by:
      build in interface JsonBuilder
      Returns:
      The compiled JSON object with all values set through this builder.
      Throws:
      BuildException
    • convertToJSON

      public Json convertToJSON() throws BuildException
      Description copied from interface: JsonGenerator
      Convert the current Java Class into a Java-JSON JSON representation of itself.
      Specified by:
      convertToJSON in interface JsonGenerator
      Returns:
      The Java-JSON representation of this class as a JSON object.
      Throws:
      BuildException
    • addBoolean

      public JsonBuilder addBoolean​(String path, boolean value) throws BuildException
      Description copied from interface: JsonBuilder
      Add a boolean to this JSON object.
      Specified by:
      addBoolean in interface JsonBuilder
      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

      public JsonBuilder addLong​(String path, long value) throws BuildException
      Description copied from interface: JsonBuilder
      Add a long to this JSON object.
      Specified by:
      addLong in interface JsonBuilder
      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

      public JsonBuilder addDouble​(String path, double value) throws BuildException
      Description copied from interface: JsonBuilder
      Add a double to this JSON object.
      Specified by:
      addDouble in interface JsonBuilder
      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

      public JsonBuilder addString​(String path, String value) throws BuildException
      Description copied from interface: JsonBuilder
      Add a string to this JSON object.
      Specified by:
      addString in interface JsonBuilder
      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

      public JsonBuilder addBuilderBlock​(String path, JsonBuilder value) throws BuildException
      Description copied from interface: JsonBuilder
      Add another JsonBuilder (representing an object) with partially filled values to this JSON object.
      Specified by:
      addBuilderBlock in interface JsonBuilder
      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

      public JsonBuilder addBuilderBlock​(String path, Json value) throws BuildException
      Description copied from interface: JsonBuilder
      Use an existing, compiled piece of JSON, converted to a JsonBuilder, then assigned to the value at the path.
      Specified by:
      addBuilderBlock in interface JsonBuilder
      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

      public JsonBuilder convertFromJSON​(Json json)
      Description copied from interface: JsonBuilder
      Break a full JSON object down into a builder representation of itself to be added to.
      Specified by:
      convertFromJSON in interface JsonBuilder
      Parameters:
      json - The JSON object to break into a builder representation.
      Returns:
      The given JSON object, as a JsonBuilder.
    • toString

      public String toString()
      Overrides:
      toString in class Object