Class JSONObjectReader
- All Implemented Interfaces:
Cloneable
Returned by the parser methods. Also provides built-in support for decoding JSF (JSON Signature Format) and JEF (JSON Encryption Format) constructs.
In addition, there are methods for reading keys supplied in the JWK (JSON Web Key) format.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionJSONObjectReader(JSONObjectWriter objectWriter) Create a JSON object reader from of a writer. -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck for unread data.clone()Deep copy of JSON object reader.Read a JSON array property.getBigDecimal(String name) Read a BigDecimal property.getBigInteger(String name) Read a BigInteger property.byte[]Read a base64url encoded JSON property.ArrayList<byte[]> getBinaryArray(String name) Read an array of base64url encoded JSON strings.byte[]getBinaryConditional(String name) Conditionally read a base64url encoded JSON property.booleangetBoolean(String name) Read JSON boolean property.booleangetBooleanConditional(String name) Conditionally read a JSON boolean property.booleangetBooleanConditional(String name, boolean defaultValue) Conditionally read a JSON boolean property.Read a certificate path in JSF format.getCorePublicKey(AlgorithmPreferences algorithmPreferences) getDateTime(String name, EnumSet<ISODateTime.DatePatterns> constraints) Read a JSON dateTime property in ISO format.doubleRead a JSON double property.Read an object in JEF format.Read an object in JEF format intended for multiple recipients.booleanConditionally read a JSON null property.intRead a JSON integer property.longRead a JSON long integer property.Get root array reader.Read a public and private key in JWK format.getKeyPair(AlgorithmPreferences algorithmPreferences) Read a public and private key in JWK format.longRead a JSON long integer property.Read a Money property.Read a Money property.getMultiSignature(String signatureLabel, JSONCryptoHelper.Options options) Read and decode a JSF multi-signature object.Read a JSON object property.String[]Get JSON properties.getPropertyType(String name) Get the native JSON type of a property.getPublicKey(AlgorithmPreferences algorithmPreferences) getSignature(String signatureLabel, JSONCryptoHelper.Options options) getSignature(JSONCryptoHelper.Options options) Read and decode a JSF signature object.getSignatureChain(String signatureLabel, JSONCryptoHelper.Options options) Read and decode a JSF chained-signature object.Read a JSON string property.String[]getStringArray(String name) Read an array of JSON strings.String[]Conditionally read an array of JSON strings.getStringConditional(String name) Conditionally read a JSON string property.
Note: This method is equivalent togetStringConditional(name, null).getStringConditional(String name, String defaultValue) Conditionally read a JSON string property.booleanhasProperty(String name) Test if a property is present.removeProperty(String name) Remove a property.Scan a property.byte[]serializeToBytes(JSONOutputFormats outputFormat) Serialize object reader to a Javabyte[].serializeToString(JSONOutputFormats outputFormat) Serialize object reader to a JavaString.toString()Pretty print JSON of object reader.
-
Constructor Details
-
JSONObjectReader
Create a JSON object reader from of a writer.- Parameters:
objectWriter- The writer object
-
-
Method Details
-
checkForUnread
public void checkForUnread()Check for unread data. Throws an exception if any property or array element in the current object or child objects have not been read.- See Also:
-
getString
Read a JSON string property.- Parameters:
name- Property- Returns:
- Java
String - See Also:
-
getInt
Read a JSON integer property.This method only accepts true integer values. I.e. 10.4 would throw an exception.
- Parameters:
name- Property- Returns:
- Java
int - See Also:
-
getInt53
Read a JSON long integer property.This method only accepts true integer values. I.e. 10.4 would throw an exception.
Note: Only 53 bits of precision is available, values outside this range throw exceptions.
- Parameters:
name- Property- Returns:
- Java
long - See Also:
-
getLong
Read a JSON long integer property.This method only accepts true integer values. I.e. 10.4 would throw an exception.
Note: The value is put within quotes to maintain full 64-bit precision which does not have a native counterpart in JavaScript.
- Parameters:
name- Property- Returns:
- Java
long - See Also:
-
getDouble
Read a JSON double property.- Parameters:
name- Property- Returns:
- Java
double - See Also:
-
getBoolean
Read JSON boolean property.- Parameters:
name- Property- Returns:
- Java
boolean - See Also:
-
getDateTime
Read a JSON dateTime property in ISO format.Note: Since JSON does not support a native dateTime type, this method builds on mapping.
- Parameters:
name- Propertyconstraints- Required input format- Returns:
- Java
GregorianCalendar - See Also:
-
getBinary
Read a base64url encoded JSON property.- Parameters:
name- Property- Returns:
- Java
byte[] - See Also:
-
getBinaryConditional
Conditionally read a base64url encoded JSON property.- Parameters:
name- Property- Returns:
- Java
byte[]or null if property is not present - See Also:
-
getMoney
Read a Money property.Note: Since JSON does not support a native Money type, this method builds on mapping.
- Parameters:
name- Property- Returns:
- Java
BigInteger - See Also:
-
getMoney
Read a Money property.Note: Since JSON does not support a native Money type, this method builds on mapping.
- Parameters:
name- Propertydecimals- Required number of fractional digits or null if unspecified- Returns:
- Java
BigDecimal - See Also:
-
getBigDecimal
Read a BigDecimal property.Note: Since JSON does not support a native BigDecimal type, this method builds on mapping.
- Parameters:
name- Property- Returns:
- Java
BigInteger - See Also:
-
getBigInteger
Read a BigInteger property.Note: Since JSON does not support a native BigInteger type, this method builds on mapping.
- Parameters:
name- Property- Returns:
- Java
BigInteger - See Also:
-
getJSONArrayReader
Get root array reader.If the outermost part of the JSON structure is an array, this method must be called immediately after parsing in order to process the structure.
- Returns:
- Array reader if array else null
- See Also:
-
getIfNULL
Conditionally read a JSON null property.Note: Only if the property contains a null the property is marked as "read".
- Parameters:
name- Property- Returns:
trueif null was found, elsefalse- See Also:
-
getObject
Read a JSON object property.- Parameters:
name- Property- Returns:
- Object reader
-
getArray
Read a JSON array property.- Parameters:
name- Property- Returns:
- Array reader
-
getStringConditional
Conditionally read a JSON string property.
Note: This method is equivalent togetStringConditional(name, null).- Parameters:
name- Property- Returns:
- The
Stringif available else null
-
getStringConditional
Conditionally read a JSON string property.- Parameters:
name- PropertydefaultValue- Default value including possibly null- Returns:
- The
Stringif available elsedefaultValue
-
getBooleanConditional
Conditionally read a JSON boolean property.- Parameters:
name- Property- Returns:
- The boolean if available else
false
-
getBooleanConditional
Conditionally read a JSON boolean property.- Parameters:
name- PropertydefaultValue- Default value- Returns:
- The boolean if available else
defaultValue
-
getStringArrayConditional
Conditionally read an array of JSON strings.- Parameters:
name- Property- Returns:
- Array of
Stringor null if property is not present
-
getStringArray
Read an array of JSON strings.- Parameters:
name- Property- Returns:
- Array of
String
-
getBinaryArray
Read an array of base64url encoded JSON strings.- Parameters:
name- Property- Returns:
- ArrayList holding arrays of bytes
-
getProperties
Get JSON properties.- Returns:
- All properties of the current object
-
hasProperty
Test if a property is present.- Parameters:
name- Property- Returns:
trueif object is present, elsefalse- See Also:
-
getPropertyType
Get the native JSON type of a property.- Parameters:
name- Property- Returns:
- JSON type
- See Also:
-
getSignature
Read and decode a JSF signature object.- Parameters:
options- Allowed/expected options- Returns:
- An object which can be used to verify keys etc.
- See Also:
-
getSignature
-
getMultiSignature
Read and decode a JSF multi-signature object.- Parameters:
options- Allowed/expected options- Returns:
- List with signature objects
-
getMultiSignature
public ArrayList<JSONSignatureDecoder> getMultiSignature(String signatureLabel, JSONCryptoHelper.Options options) -
getSignatureChain
Read and decode a JSF chained-signature object.- Parameters:
options- Allowed/expected options- Returns:
- List with signature objects
-
getSignatureChain
public ArrayList<JSONSignatureDecoder> getSignatureChain(String signatureLabel, JSONCryptoHelper.Options options) -
getPublicKey
- Parameters:
algorithmPreferences- JOSE or SKS notation expected- Returns:
- Java
PublicKey - See Also:
-
getPublicKey
Read and decode a public key in JSF (JWK) format. This method is equivalent togetPublicKey(AlgorithmPreferences.JOSE).- Returns:
- Java
PublicKey - See Also:
-
getCorePublicKey
Read and decode a public key in JSF (JWK) format. Note: this method assumes that the current object only holds the actual public key structure (no property).- Parameters:
algorithmPreferences- JOSE or SKS notation expected- Returns:
- Java
PublicKey - See Also:
-
getKeyPair
Read a public and private key in JWK format.Note: this method assumes that the current object only holds a JWK key structure.
- Parameters:
algorithmPreferences- JOSE or SKS notation expected- Returns:
- Java
KeyPair
-
getKeyPair
Read a public and private key in JWK format.Note: this method assumes that the current object only holds a JWK key structure.
This method is equivalent togetKeyPair(AlgorithmPreferences.JOSE).- Returns:
- Java
KeyPair
-
getEncryptionObject
Read an object in JEF format.Note: this method assumes that the current object only holds a JEF structure.
- Parameters:
options- Restrictions and requirements- Returns:
- An object which can be used to retrieve the original (unencrypted) data
- See Also:
-
getEncryptionObjects
Read an object in JEF format intended for multiple recipients.Note: this method assumes that the current object only holds a JEF structure.
- Parameters:
options- Global restrictions and requirements- Returns:
- An object which can be used to retrieve the original (unencrypted) data
- See Also:
-
getCertificatePath
Read a certificate path in JSF format.The array elements (base64url encoded certificates), must be supplied in strict issuance order where certificate[i] is signed by certificate[i + 1].
- Returns:
- Certificate path
- See Also:
-
scanAway
Scan a property. This method scans a property regardless of its type and it useful for dealing with data where the type is unknown. It also marks the property as "read" including possible child objects and arrays.- Parameters:
name- Property- Returns:
- Current instance of
JSONObjectReader - See Also:
-
removeProperty
Remove a property.- Parameters:
name- Property- Returns:
- Current instance of
JSONObjectReader
-
serializeToBytes
Serialize object reader to a Javabyte[].- Parameters:
outputFormat- Any JSONOutputFormats- Returns:
- JSON string data
-
serializeToString
Serialize object reader to a JavaString.- Parameters:
outputFormat- Any JSONOutputFormats- Returns:
- JSON string data
-
clone
Deep copy of JSON object reader. -
toString
Pretty print JSON of object reader.
-