Class JSONBuilder
java.lang.Object
org.incenp.obofoundry.sssom.util.JSONBuilder
A helper class to assemble a JSON string.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a key in the current dictionary.voidaddValue(boolean value) Adds a boolean value at the current position.voidAdds a floating point value at the current position.voidAdds an arbitrary value at the current position.voidAdds a string value at the current position.close()Closes all open structures and returns the resulting JSON string.voidend()Closes the current list or dictionary, whichever it is.voidendDict()Closes the current dictionary.voidendList()Closes the current list.voidStarts a new dictionary at the current position.voidStarts a new list at the current position.
-
Constructor Details
-
JSONBuilder
public JSONBuilder()
-
-
Method Details
-
startDict
public void startDict()Starts a new dictionary at the current position. -
endDict
public void endDict()Closes the current dictionary.This is a no-op if the current structure is not, in fact, a dictionary.
-
startList
public void startList()Starts a new list at the current position. -
endList
public void endList()Closes the current list.This is a no-op if the current structure is not, in fact, a list.
-
end
public void end()Closes the current list or dictionary, whichever it is. -
addKey
Adds a key in the current dictionary.If the current structure is not already a dictionary, a new dictionary is automatically started.
- Parameters:
key- The name of the key to add.
-
addValue
Adds a string value at the current position.- Parameters:
value- The value to add.
-
addValue
public void addValue(boolean value) Adds a boolean value at the current position.- Parameters:
value- The value to add.
-
addValue
Adds a floating point value at the current position.- Parameters:
value- The value to add.
-
addValue
Adds an arbitrary value at the current position.- Parameters:
value- The value to add.
-
close
Closes all open structures and returns the resulting JSON string.This automatically clears the builder, which can then be reused to build a new JSON string.
- Returns:
- The assembled JSON string.
-