Interface JSONBuilder
- All Known Implementing Classes:
JSONBuilderImpl
This sealed interface is the main API for the Foundation JSON Builder Library.
getInstance() returns an instance of an implementation for the
interface.
Basically, the instances of JSONBuilder are stateless, and
therefore they can be treated as thread-safe. Only the
indentation
that is used for pretty-printing the resulting JSON values may cause issues
when different threads are using different values.
The different implementations of
JSONValue
– particularly
JSONObject
and
JSONArray
are not thread-safe.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: JSONBuilder.java 1258 2026-06-04 18:33:06Z tquadrat $
- Since:
- 0.25.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.jsonbuilder.JSONBuilder"
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe indentation that is used when aJSONValueis formatted: 2.static final StringThe name of the JSON String that holds the unit for the dimension from aDimensionedValue: "Unit".static final StringThe name of the JSON Number that holds the value from aDimensionedValue: "Value". -
Method Summary
Modifier and TypeMethodDescriptiondefault JSONArrayReturns a deep copy of the given JSON array.default JSONObjectcopyObject(JSONObject source) Returns a deep copy of the given JSON object.Returns a new empty instance ofJSONArray.default JSONArraycreateArray(double[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(float[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(int elementCount) Returns a new instance ofJSONArraywith the given number of elements, all set toJSONLiteral.NULL.default JSONArraycreateArray(int[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(long[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(Double[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(Float[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(Integer[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(Long[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(String... values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(BigDecimal[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(BigInteger[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.default JSONArraycreateArray(Supplier<JSONValue[]> supplier) Returns a new instance ofJSONArraythat is populated with the return value from the givenSupplier<JSONValue []>.default JSONArraycreateArray(JSONValue[] values) Returns a new instance ofJSONArraythat is populated with the values from the given array.Returns a new empty instance ofJSONObject.default JSONObjectcreateObject(Collection<String> names, Function<String, JSONValue> provider) Returns a new instance ofJSONObjectthat is populated with the values returned by the givenFunction.intReturns the indentation that is used when aJSONValueis formatted.static JSONBuilderCreates an instance ofJSONBuilder.voidsetIndentation(int value) Sets the indentation that is used when aJSONValueis formatted for pretty-printing.default JSONLiteralvalueOf(boolean value) Returns aJSONValueinstance that represents the givenbooleanvalue.valueOf(double value) Returns aJSONValueinstance that represents the givendoublevalue.valueOf(float value) Returns aJSONValueinstance that represents the givenfloatvalue.valueOf(int value) Returns aJSONValueinstance that represents the givenintvalue.valueOf(long value) Returns aJSONValueinstance that represents the givenlongvalue.valueOf(BigDecimal value) Returns aJSONValueinstance that represents the givenBigDecimalvalue.valueOf(BigInteger value) Returns aJSONValueinstance that represents the givenBigIntegervalue.default <T extends Dimension>
JSONObjectvalueOf(DimensionedValue<T> value, T targetUnit) Returns aJSONValueinstance (more precisely, an instance ofJSONObject) that represents the givenDimensionedValueinstance.default JSONLiteralReturns aJSONValueinstance that represents thenullvalue.
-
Field Details
-
DEFAULT_INDENTATION
The indentation that is used when aJSONValueis formatted: 2.- See Also:
-
JSONField_Unit
The name of the JSON String that holds the unit for the dimension from aDimensionedValue: "Unit".- See Also:
-
JSONField_Value
The name of the JSON Number that holds the value from aDimensionedValue: "Value".- See Also:
-
-
Method Details
-
copyArray
-
copyObject
Returns a deep copy of the given JSON object.
- Parameters:
source- The object to copy.- Returns:
- The deep copy.
-
createArray
-
createArray
Returns a new instance of
JSONArraywith the given number of elements, all set toJSONLiteral.NULL.- Parameters:
elementCount- The number of elements for the new array.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the return value from the givenSupplier<JSONValue []>.- Parameters:
supplier- The supplier for the array.- Returns:
- The new array.
-
createArray
Returns a new instance of
JSONArraythat is populated with the values from the given array.- Parameters:
values- The values.- Returns:
- The new array.
-
createObject
-
createObject
Returns a new instance of
JSONObjectthat is populated with the values returned by the givenFunction.The function's argument is the name of the new member, provided by the
namesargument to this method.- Parameters:
names- The member names for the new object.provider- The function that returns the value for the member with the given name.- Returns:
- The new object.
-
getIndentation
int getIndentation()Returns the indentation that is used when a
JSONValueis formatted. If not set explicitly through a call tosetIndentation(int), the default value (2) will be returned.- Returns:
- The indentation.
- See Also:
-
setIndentation
Sets the indentation that is used when a
JSONValueis formatted for pretty-printing.- Parameters:
value- The indentation.- See Also:
-
getInstance
Creates an instance of
JSONBuilder.Each call to this method will return a new instance of
JSONBuilder.- Returns:
- A new instance of
JSONBuilder.
-
valueOf
Returns aJSONValueinstance that represents the givenBigDecimalvalue.- Parameters:
value- The value.- Returns:
- The JSON value that represents the given value.
-
valueOf
Returns aJSONValueinstance that represents the givenBigIntegervalue.- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
Returns aJSONValueinstance that represents the givenbooleanvalue.- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
Returns a
JSONValueinstance (more precisely, an instance ofJSONObject) that represents the givenDimensionedValueinstance.The member names are "Unit" for the dimension, and "Value" for the numerical value.
- Type Parameters:
T- The type of the dimension for the value.- Parameters:
value- The value.targetUnit- The dimension for the output.- Returns:
- The resulting JSON object.
-
valueOf
Returns aJSONValueinstance that represents the givendoublevalue.- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
Returns aJSONValueinstance that represents the givenfloatvalue.- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
Returns aJSONValueinstance that represents the givenintvalue.- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
Returns aJSONValueinstance that represents the givenlongvalue.- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOf
- Parameters:
value- The value- Returns:
- The JSON value that represents the given value.
-
valueOfNull
Returns aJSONValueinstance that represents thenullvalue.- Returns:
- The JSON value that represents
null.
-
