Package com.tccc.kos.commons.util.json
Class JsonDescriptor
java.lang.Object
com.tccc.kos.commons.util.json.JsonDescriptor
Encapsulation of a descriptor file used by various resources such as
KAB files and assemblies. This is a generic way to load a json structure
into an internal representation which can then be accessed using dotted
notation. This supports fetching individual values using dotted notation
as well as deserializing entire sections of the graph using dotted notation
and a class.
This object will serialize to json as the a raw json graph.
- Since:
- 1.0
- Version:
- 2022-09-28
-
Constructor Summary
ConstructorsConstructorDescriptionJsonDescriptor
(JsonNode root) Create a new descriptor with the root node.JsonDescriptor
(File file) Create a new descriptor from a file.Create a new descriptor from an input stream. -
Method Summary
Modifier and TypeMethodDescription<T> T
Finds the specified node in the descriptor using dotted notation, and then either converts to the specified type or returns null.<T> T
Finds the specified node in the descriptor using dotted notation, and then either converts to the specified type or returns null.boolean
getBoolean
(String path) Return the boolean value of the specified node.boolean
getBoolean
(String path, boolean def) Return the boolean value of the specified node and return the default value if not found or null.double
Return the double value of the specified node.double
Return the long value of the specified node and return the default value if not found or null.int
Return the int value of the specified node.int
Return the int value of the specified node and return the default value if not found or null.long
Return the long value of the specified node.long
Return the long value of the specified node and return the default value if not found or null.Finds the specified node in the descriptor using dotted notation.<T> T
getNonNullBean
(String path, Class<T> clazz) Finds the specified node in the descriptor using dotted notation, and then either converts to the specified type or returns a new instance of the class.getRoot()
Return the string value of the specified node.Return the string value of the specified node and return the default value if not found or null.
-
Constructor Details
-
JsonDescriptor
Create a new descriptor from a file.- Parameters:
file
- the file containing the descriptor json- Throws:
IOException
-
JsonDescriptor
Create a new descriptor from an input stream.- Parameters:
is
- input stream containing the descriptor json- Throws:
IOException
-
JsonDescriptor
Create a new descriptor with the root node.- Parameters:
root
- the root node of the descriptor json
-
-
Method Details
-
getNode
Finds the specified node in the descriptor using dotted notation.- Parameters:
path
- dotted notation of fields
-
getString
Return the string value of the specified node.- Parameters:
path
- dotted notation of the fields
-
getString
Return the string value of the specified node and return the default value if not found or null.- Parameters:
path
- dotted notation of the fieldsdef
- the default value
-
getInt
Return the int value of the specified node.- Parameters:
path
- dotted notation of the fields- Returns:
- int value of the node or 0
-
getInt
Return the int value of the specified node and return the default value if not found or null.- Parameters:
path
- dotted notation of the fieldsdef
- the default value
-
getLong
Return the long value of the specified node.- Parameters:
path
- dotted notation of the fields- Returns:
- long value of the node or 0
-
getLong
Return the long value of the specified node and return the default value if not found or null.- Parameters:
path
- dotted notation of the fieldsdef
- the default value
-
getDouble
Return the double value of the specified node.- Parameters:
path
- dotted notation of the fields- Returns:
- double value of the node or 0
-
getDouble
Return the long value of the specified node and return the default value if not found or null.- Parameters:
path
- dotted notation of the fieldsdef
- the default value
-
getBoolean
Return the boolean value of the specified node.- Parameters:
path
- dotted notation of the fields- Returns:
- boolean value of the node or false
-
getBoolean
Return the boolean value of the specified node and return the default value if not found or null.- Parameters:
path
- dotted notation of the fieldsdef
- the default value
-
getBean
Finds the specified node in the descriptor using dotted notation, and then either converts to the specified type or returns null.- Parameters:
path
- dotted notation of fieldsclazz
- the type to convert to
-
getNonNullBean
Finds the specified node in the descriptor using dotted notation, and then either converts to the specified type or returns a new instance of the class.- Parameters:
path
- dotted notation of fieldsclazz
- the type to convert to
-
getBean
Finds the specified node in the descriptor using dotted notation, and then either converts to the specified type or returns null.- Parameters:
path
- dotted notation of fieldstype
- the type to convert to
-
getRoot
-