public class JSONBuilder extends Object
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 and Description |
---|
JSONBuilder() |
Modifier and Type | Method and Description |
---|---|
JSONBuilder |
array(String key,
Object... values)
Puts an array.
|
JSONBuilder |
object(String key)
Creates an object for the given key.
|
JSONBuilder |
put(String key,
Instant value)
Puts an
Instant to the JSON. |
JSONBuilder |
put(String key,
Object value)
Puts a property.
|
JSONBuilder |
putBase64(String key,
byte[] data)
Puts binary data to the JSON.
|
JSONBuilder |
putKey(String key,
PublicKey publickey)
Puts a
Key into the claim. |
JSONBuilder |
putResource(Resource resource)
Puts a resource.
|
JSONBuilder |
putResource(String resource)
Puts a resource.
|
JSON |
toJSON()
Returns a
JSON representation of the current state. |
Map<String,Object> |
toMap()
Returns a
Map representation of the current state. |
String |
toString()
Returns a JSON string representation of the current state.
|
public JSONBuilder()
public JSONBuilder put(String key, Object value)
key
- Property keyvalue
- Property valuethis
public JSONBuilder put(String key, Instant value)
Instant
to the JSON. If a property with the key exists, it will be
replaced.key
- Property keyvalue
- Property Instant
valuethis
public JSONBuilder putResource(String resource)
resource
- Resource namethis
public JSONBuilder putResource(Resource resource)
resource
- Resource
this
public JSONBuilder putBase64(String key, byte[] data)
key
- Property keydata
- Property datathis
public JSONBuilder putKey(String key, PublicKey publickey)
Key
into the claim. The key is serializied as JWK.key
- Property keypublickey
- PublicKey
to serializethis
public JSONBuilder object(String key)
key
- Key of the objectJSONBuilder
for the object.public JSONBuilder array(String key, Object... values)
key
- Property keyvalues
- Array of property valuesthis
public Map<String,Object> toMap()
Map
representation of the current state.Map
of the current statepublic JSON toJSON()
JSON
representation of the current state.JSON
of the current stateCopyright © 2015–2019. All rights reserved.