Package dev.tachyonmcp.api.json
Interface JsonObject
- All Superinterfaces:
JsonDocument
- All Known Implementing Classes:
Args
An immutable, provider-neutral view of a JSON object.
Missing properties and JSON null produce empty optionals. Accessing a property as the
wrong type, narrowing a fraction to an integer, or overflowing the requested numeric type throws
IllegalArgumentException. Numeric strings and other scalar types are never coerced.
Implementations may retain a provider-specific representation and expose it through JsonDocument.unwrap(Class).
- Author:
- Konstantin Pavlov
-
Method Summary
Modifier and TypeMethodDescriptionReturns the named array, or an empty optional when it is missing or JSON null.default JsonArrayReturns the named array orfallbackwhen it is missing or JSON null.default JsonArrayarrayValue(String name) Returns the named required array.asMap()Returns an immutable map representation.Returns the named boolean, or an empty optional when it is missing or JSON null.default booleanReturns the named boolean orfallbackwhen it is missing or JSON null.default booleanReturns the named required boolean.decimalOpt(String name) Returns the named number without precision loss.default BigDecimaldecimalOr(String name, BigDecimal fallback) Returns the named decimal orfallbackwhen it is missing or JSON null.default BigDecimaldecimalValue(String name) Returns the named required number without precision loss.Returns the named value converted to a finitedouble.default doubleReturns the named finitedoubleorfallbackwhen missing or JSON null.default doubledoubleValue(String name) Returns the named required finitedouble.static JsonObjectempty()Returns an empty JSON object.booleanReturns whether the object has propertyname, including when its value is JSON null.Returns the named exactint.default intReturns the named exactintorfallbackwhen it is missing or JSON null.default intReturns the named required exactint.Returns the named exactlong.default longReturns the named exactlongorfallbackwhen it is missing or JSON null.default longReturns the named required exactlong.Returns the named object, or an empty optional when it is missing or JSON null.default JsonObjectobjectOr(String name, JsonObject fallback) Returns the named object orfallbackwhen it is missing or JSON null.default JsonObjectobjectValue(String name) Returns the named required object.static JsonObjectCreates an immutable object by recursively snapshotting JSON-compatible values.Returns the named string, or an empty optional when it is missing or JSON null.default StringReturns the named string orfallbackwhen it is missing or JSON null.default StringstringValue(String name) Returns the named required string.Methods inherited from interface dev.tachyonmcp.api.json.JsonDocument
json, unwrap
-
Method Details
-
has
Returns whether the object has propertyname, including when its value is JSON null.- Parameters:
name- the property name- Returns:
- true if the property exists
-
objectOpt
Returns the named object, or an empty optional when it is missing or JSON null.- Parameters:
name- the property name- Returns:
- the object value, or empty if missing or null
-
arrayOpt
Returns the named array, or an empty optional when it is missing or JSON null.- Parameters:
name- the property name- Returns:
- the array value, or empty if missing or null
-
stringOpt
Returns the named string, or an empty optional when it is missing or JSON null.- Parameters:
name- the property name- Returns:
- the string value, or empty if missing or null
-
boolOpt
Returns the named boolean, or an empty optional when it is missing or JSON null.- Parameters:
name- the property name- Returns:
- the boolean value, or empty if missing or null
-
decimalOpt
Returns the named number without precision loss.- Parameters:
name- the property name- Returns:
- the decimal value, or empty if missing or null
-
intOpt
Returns the named exactint.- Parameters:
name- the property name- Returns:
- the int value, or empty if missing or null
- Throws:
IllegalArgumentException- if the value is not a number or is not exactly representable as anint
-
longOpt
Returns the named exactlong.- Parameters:
name- the property name- Returns:
- the long value, or empty if missing or null
- Throws:
IllegalArgumentException- if the value is not a number or is not exactly representable as along
-
doubleOpt
Returns the named value converted to a finitedouble.The conversion may lose precision. Use
decimalOpt(String)when an exact decimal representation is required.- Parameters:
name- the property name- Returns:
- the double value, or empty if missing or null
-
objectValue
Returns the named required object.- Parameters:
name- the property name- Returns:
- the object value
- Throws:
IllegalArgumentException- if the property is missing or null
-
arrayValue
Returns the named required array.- Parameters:
name- the property name- Returns:
- the array value
- Throws:
IllegalArgumentException- if the property is missing or null
-
stringValue
Returns the named required string.- Parameters:
name- the property name- Returns:
- the string value
- Throws:
IllegalArgumentException- if the property is missing or null
-
boolValue
Returns the named required boolean.- Parameters:
name- the property name- Returns:
- the boolean value
- Throws:
IllegalArgumentException- if the property is missing or null
-
decimalValue
Returns the named required number without precision loss.- Parameters:
name- the property name- Returns:
- the decimal value
- Throws:
IllegalArgumentException- if the property is missing or null
-
intValue
Returns the named required exactint.- Parameters:
name- the property name- Returns:
- the int value
- Throws:
IllegalArgumentException- if the property is missing or null
-
longValue
Returns the named required exactlong.- Parameters:
name- the property name- Returns:
- the long value
- Throws:
IllegalArgumentException- if the property is missing or null
-
doubleValue
Returns the named required finitedouble.- Parameters:
name- the property name- Returns:
- the double value
- Throws:
IllegalArgumentException- if the property is missing or null
-
objectOr
Returns the named object orfallbackwhen it is missing or JSON null.- Parameters:
name- the property namefallback- the fallback value- Returns:
- the object value, or fallback
-
arrayOr
Returns the named array orfallbackwhen it is missing or JSON null.- Parameters:
name- the property namefallback- the fallback value- Returns:
- the array value, or fallback
-
stringOr
Returns the named string orfallbackwhen it is missing or JSON null.- Parameters:
name- the property namefallback- the fallback value- Returns:
- the string value, or fallback
-
boolOr
Returns the named boolean orfallbackwhen it is missing or JSON null.- Parameters:
name- the property namefallback- the fallback value- Returns:
- the boolean value, or fallback
-
decimalOr
Returns the named decimal orfallbackwhen it is missing or JSON null.- Parameters:
name- the property namefallback- the fallback value- Returns:
- the decimal value, or fallback
-
intOr
Returns the named exactintorfallbackwhen it is missing or JSON null.- Parameters:
name- the property namefallback- the fallback value- Returns:
- the int value, or fallback
-
longOr
Returns the named exactlongorfallbackwhen it is missing or JSON null.- Parameters:
name- the property namefallback- the fallback value- Returns:
- the long value, or fallback
-
doubleOr
Returns the named finitedoubleorfallbackwhen missing or JSON null.- Parameters:
name- the property namefallback- the fallback value- Returns:
- the double value, or fallback
-
asMap
Returns an immutable map representation.- Returns:
- the map view
-
of
Creates an immutable object by recursively snapshotting JSON-compatible values.- Parameters:
values- the source map- Returns:
- a new JSON object
-
empty
Returns an empty JSON object.- Returns:
- the empty instance
-