public abstract class SqllrObject extends Object
Values. A member holds a JSON value: a Map with string keys, a List, a String, a
Long (or a BigInteger outside the range of long), a Boolean, or JSON null. Integers
given as Integer, Short, Byte or a BigInteger that fits are stored as Long,
so two objects with the same JSON are equal however they were built. Every member is kept, including members the
model does not type (extensions, module content, members of a later minor version): reading a document and
writing it again loses nothing.
Absence and null. A typed getter returns null when the member is absent and throws
IllegalStateException when the member holds JSON of another type, JSON null included. A getter typed
Object (any JSON value) returns JSON_NULL for a member that is present with JSON null. A builder
setter given null removes the member; given JSON_NULL it sets JSON null.
Immutability and cost. Objects are immutable and thread-safe; a SqllrObject.Builder makes a changed copy.
Values are frozen once, without recursion, so any depth the strict reader accepts is supported. A typed getter
computes its view once and returns the same object afterwards. Equality compares the canonical JSON
(RFC 8785) of the members.
The model checks shapes only when a typed accessor reads a member; it does not validate. Use
LineageValidator for that.
| Modifier and Type | Class and Description |
|---|---|
static class |
SqllrObject.Builder<T extends SqllrObject,B extends SqllrObject.Builder<T,B>>
Collects the members of a new object.
|
static interface |
SqllrObject.Reader<T>
Converts one JSON value to a typed value.
|
| Modifier and Type | Field and Description |
|---|---|
protected static SqllrObject.Reader<Object> |
ANY
Reads any JSON value as it is (JSON null as null).
|
protected static SqllrObject.Reader<Boolean> |
BOOLEAN
Reads a JSON boolean.
|
protected static SqllrObject.Reader<Long> |
INTEGER
Reads a JSON integer.
|
static Object |
JSON_NULL
JSON null as a member value, distinct from an absent member; see the class description.
|
protected static SqllrObject.Reader<Map<String,Object>> |
OBJECT
Reads a JSON object as a map.
|
protected static SqllrObject.Reader<String> |
STRING
Reads a JSON string.
|
| Modifier | Constructor and Description |
|---|---|
protected |
SqllrObject(Map<String,Object> members) |
| Modifier and Type | Method and Description |
|---|---|
protected Object |
anyMember(String member)
Any JSON value: null when absent,
JSON_NULL when present with JSON null. |
protected Boolean |
bool(String member) |
boolean |
equals(Object other) |
Object |
get(String member)
The raw JSON value of a member: null when absent or JSON null (see
has(java.lang.String)). |
boolean |
has(String member) |
int |
hashCode() |
protected Long |
integer(String member) |
protected <T> List<T> |
list(String member,
SqllrObject.Reader<T> reader) |
protected static <T> SqllrObject.Reader<List<T>> |
listOf(SqllrObject.Reader<T> item)
Reads a JSON array, each item with a reader, as an unmodifiable list.
|
protected <T> Map<String,T> |
map(String member,
SqllrObject.Reader<T> reader) |
protected static <T> SqllrObject.Reader<Map<String,T>> |
mapOf(SqllrObject.Reader<T> item)
Reads a JSON object, each member with a reader, as an unmodifiable map.
|
protected static Map<String,Object> |
members(Object json,
String type)
The members of a JSON object as frozen JSON values (a frozen tree is used as it is, not copied).
|
protected Map<String,Object> |
object(String member) |
protected String |
string(String member) |
Map<String,Object> |
toJson()
The members as a frozen JSON object, in the order they were set.
|
String |
toString()
The RFC 8785 text of the object.
|
protected <T> T |
typed(String member,
SqllrObject.Reader<T> reader) |
public static final Object JSON_NULL
protected static final SqllrObject.Reader<String> STRING
protected static final SqllrObject.Reader<Long> INTEGER
protected static final SqllrObject.Reader<Boolean> BOOLEAN
protected static final SqllrObject.Reader<Object> ANY
protected static final SqllrObject.Reader<Map<String,Object>> OBJECT
protected SqllrObject(Map<String,Object> members)
protected static Map<String,Object> members(Object json, String type)
public final Object get(String member)
has(java.lang.String)).public final Map<String,Object> toJson()
protected final Object anyMember(String member)
JSON_NULL when present with JSON null.protected final <T> T typed(String member, SqllrObject.Reader<T> reader)
protected final <T> List<T> list(String member, SqllrObject.Reader<T> reader)
protected final <T> Map<String,T> map(String member, SqllrObject.Reader<T> reader)
protected static <T> SqllrObject.Reader<List<T>> listOf(SqllrObject.Reader<T> item)
protected static <T> SqllrObject.Reader<Map<String,T>> mapOf(SqllrObject.Reader<T> item)