- java.lang.Object
-
- org.shredzone.acme4j.toolbox.JSONBuilder
-
public class JSONBuilder extends Object
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 Constructor Description JSONBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JSONBuilder
array(String key, Collection<?> values)
Puts an array.JSONBuilder
object(String key)
Creates an object for the given key.JSONBuilder
put(String key, Object value)
Puts a property.JSONBuilder
put(String key, Duration value)
Puts aDuration
to the JSON.JSONBuilder
put(String key, Instant value)
Puts anInstant
to the JSON.JSONBuilder
putBase64(String key, byte[] data)
Puts binary data to the JSON.JSONBuilder
putKey(String key, PublicKey publickey)
Puts aKey
into the claim.JSON
toJSON()
Returns aJSON
representation of the current state.Map<String,Object>
toMap()
Returns aMap
representation of the current state.String
toString()
Returns a JSON string representation of the current state.
-
-
-
Constructor Detail
-
JSONBuilder
public JSONBuilder()
-
-
Method Detail
-
put
public JSONBuilder put(String key, @Nullable Object value)
Puts a property. If a property with the key exists, it will be replaced.- Parameters:
key
- Property keyvalue
- Property value- Returns:
this
-
put
public JSONBuilder put(String key, @Nullable Instant value)
Puts anInstant
to the JSON. If a property with the key exists, it will be replaced.- Parameters:
key
- Property keyvalue
- PropertyInstant
value- Returns:
this
-
put
public JSONBuilder put(String key, @Nullable Duration value)
Puts aDuration
to the JSON. If a property with the key exists, it will be replaced.- Parameters:
key
- Property keyvalue
- PropertyDuration
value- Returns:
this
- Since:
- 2.3
-
putBase64
public JSONBuilder putBase64(String key, byte[] data)
Puts binary data to the JSON. The data is base64 url encoded.- Parameters:
key
- Property keydata
- Property data- Returns:
this
-
putKey
public JSONBuilder putKey(String key, PublicKey publickey)
Puts aKey
into the claim. The key is serializied as JWK.- Parameters:
key
- Property keypublickey
-PublicKey
to serialize- Returns:
this
-
object
public JSONBuilder object(String key)
Creates an object for the given key.- Parameters:
key
- Key of the object- Returns:
- Newly created
JSONBuilder
for the object.
-
array
public JSONBuilder array(String key, Collection<?> values)
Puts an array.- Parameters:
key
- Property keyvalues
- Collection of property values- Returns:
this
-
toMap
public Map<String,Object> toMap()
Returns aMap
representation of the current state.- Returns:
Map
of the current state
-
toJSON
public JSON toJSON()
Returns aJSON
representation of the current state.- Returns:
JSON
of the current state
-
-