java.lang.Object
org.shredzone.acme4j.toolbox.JSONBuilder
Builder for JSON structures.
Example:
JSONBuilder cb = new JSONBuilder();
cb.put("foo", 123).put("bar", "hello world");
cb.object("sub").put("data", "subdata");
cb.array("array", 123, 456, 789);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionarray(String key, Collection<?> values) Puts an array.Creates an object for the given key.Puts a property.Puts aDurationto the JSON.Puts anInstantto the JSON.Puts binary data to the JSON.Puts aKeyinto the claim.toJSON()Returns aJSONrepresentation of the current state.toMap()Returns aMaprepresentation of the current state.toString()Returns a JSON string representation of the current state.
-
Constructor Details
-
JSONBuilder
public JSONBuilder()
-
-
Method Details
-
put
Puts a property. If a property with the key exists, it will be replaced.- Parameters:
key- Property keyvalue- Property value- Returns:
this
-
put
Puts anInstantto the JSON. If a property with the key exists, it will be replaced.- Parameters:
key- Property keyvalue- PropertyInstantvalue- Returns:
this
-
put
Puts aDurationto the JSON. If a property with the key exists, it will be replaced.- Parameters:
key- Property keyvalue- PropertyDurationvalue- Returns:
this- Since:
- 2.3
-
putBase64
Puts binary data to the JSON. The data is base64 url encoded.- Parameters:
key- Property keydata- Property data- Returns:
this
-
putKey
Puts aKeyinto the claim. The key is serializied as JWK.- Parameters:
key- Property keypublickey-PublicKeyto serialize- Returns:
this
-
object
Creates an object for the given key.- Parameters:
key- Key of the object- Returns:
- Newly created
JSONBuilderfor the object.
-
array
Puts an array.- Parameters:
key- Property keyvalues- Collection of property values- Returns:
this
-
toMap
Returns aMaprepresentation of the current state.- Returns:
Mapof the current state
-
toJSON
Returns aJSONrepresentation of the current state.- Returns:
JSONof the current state
-
toString
Returns a JSON string representation of the current state.
-