Interface JsonFactory<N>
- Type Parameters:
N- the node type of the caller's JSON representation
- All Known Implementing Classes:
JacksonJsonModel
Builds nodes of the caller's JSON representation.
A JsonModel gives read access, and it is enough for all standard functions of RFC 9535. A
model that also implements JsonFactory can run function extensions that make new values,
for example a function that returns a new array. A read-only model, for example a model over
a memory-mapped file, does not implement this interface.
Contract
- No exceptions. No method throws an exception.
- Exact values. For a node that a method builds, the read methods of the model give the
same value again. For example,
JsonModel.numberValue(Object)ofnumber(x)has the same exact value asx, andJsonModel.kind(Object)ofbool(true)isJsonKind.TRUE. - New nodes. A built node is not part of the query argument, so it has no location.
jsonlens calls object(List) only with unique member names. A function extension must do
the same.
-
Method Summary
Modifier and TypeMethodDescriptionBuilds an array.bool(boolean value) Buildstrueorfalse.Builds a deep copy of a value of any model, in the representation of this factory.Buildsnull.number(JsonNumber value) Builds a number.Builds an object.string(JsonString value) Builds a string.
-
Method Details
-
string
Builds a string.- Parameters:
value- the value- Returns:
- a node of kind
JsonKind.STRING
-
number
Builds a number.
A representation can have a limit. For example, a
BigDecimalcannot hold a number with an exponent outside the range ofint. Then the result isMaybe.None: the factory never builds a number with a different value.- Parameters:
value- the value- Returns:
- a node of kind
JsonKind.NUMBERwith the exact value, orMaybe.Noneif the representation cannot hold the value
-
bool
Buildstrueorfalse.- Parameters:
value- the value- Returns:
- a node of kind
JsonKind.TRUEorJsonKind.FALSE
-
nullValue
-
array
Builds an array.- Parameters:
elements- the elements, in order- Returns:
- a node of kind
JsonKind.ARRAY
-
object
Builds an object.- Parameters:
members- the members, in order. The names are unique.- Returns:
- a node of kind
JsonKind.OBJECT
-
copyOf
Builds a deep copy of a value of any model, in the representation of this factory.
The source can be a value of another JSON library, for example a value of a memory-mapped file copied into a Jackson tree. It can also be a value of this model: then the copy shares no node with the source, so a later change of the copy does not change the source. Strings and numbers go to
string(JsonString)andnumber(JsonNumber)in the representation of the source, so the factory decides if it must convert them.The method uses no recursion, so a deep value cannot overflow the stack. It never gives duplicate member names to
object(List): the copy of an object with duplicate names (seeJsonModel.hasDuplicate(Object, JsonString)) fails, because its value is not defined (RFC 8259, Section 4).- Type Parameters:
S- the node type of the source model- Parameters:
model- the model of the source valuevalue- the source value- Returns:
- the copy, or
Maybe.Noneif this representation cannot hold a number of the value, or if an object of the value has duplicate member names, or if the source model is not well-formed (it gives no element below the length of an array)
-