KotlinxObjectModel

class KotlinxObjectModel(val json: Json = Json) : JsonModel<KotlinxNode>

A read-only JsonModel over Kotlin objects, through their kotlinx.serialization serializers.

The model reads your objects directly: the JSON view of a node is the JSON that Json.encodeToJsonElement gives for it with the same Json instance, but the model does not encode a whole tree. When a query visits a node, the serializer of the node writes its direct children into a capturing encoder. A child object is kept as its value and its serializer, and it is read only when a query visits it.

val model = KotlinxObjectModel(Json)
val nodes = JsonPathEvaluator.standard().evaluate(query, model.node(order, Order.serializer()), model)
val line = nodes.first().value().value // your own object

The view follows the configuration of the Json instance: encodeDefaults, explicitNulls, the naming strategy, enums, value classes, and unsigned numbers. For a polymorphic or contextual value, a map with structured keys, a serializer that writes more than one level, and the class discriminator mode ClassDiscriminatorMode.ALL_JSON_OBJECTS, the model reads that part through Json.encodeToJsonElement, so the view is always the JSON of the instance.

The model is well-formed for values that json can encode. For a value that json cannot encode, for example Double.NaN without allowSpecialFloatingPointValues, the view is not defined, and a read can throw the exception of json.

The model is read-only: Kotlin objects are immutable. To patch an object, encode it, use JsonPatch.applyToCopy with KotlinxJsonModel, and decode the result.

Constructors

Link copied to clipboard
constructor(json: Json = Json)

Properties

Link copied to clipboard
val json: Json

the instance whose configuration gives the JSON view

Functions

Link copied to clipboard
open override fun arrayLength(array: KotlinxNode): Int
Link copied to clipboard
open fun compareNumbers(a: JsonNumber?, b: JsonNumber?): Int
Link copied to clipboard
open override fun element(array: KotlinxNode, index: Int): Maybe<KotlinxNode>
Link copied to clipboard
open fun equal(a: KotlinxNode?, b: KotlinxNode?): Boolean
Link copied to clipboard
open override fun hasDuplicate(object: KotlinxNode, name: JsonString): Boolean

The members of a shape are a map, so they cannot hold duplicate names.

Link copied to clipboard
open override fun kind(node: KotlinxNode): JsonKind
Link copied to clipboard
open override fun member(object: KotlinxNode, name: JsonString): Maybe<KotlinxNode>
Link copied to clipboard
open override fun memberCount(object: KotlinxNode): Int
Link copied to clipboard
open override fun memberCursor(object: KotlinxNode): MemberCursor<KotlinxNode>
Link copied to clipboard
open fun members(object: KotlinxNode?): Stream<Property<KotlinxNode?>?>?
Link copied to clipboard
fun <T> node(value: T, serializer: SerializationStrategy<T>): KotlinxNode

Returns the node of a value, with its serializer, for example Order.serializer().

Link copied to clipboard
open override fun numberValue(number: KotlinxNode): JsonNumber
Link copied to clipboard
open override fun stringValue(string: KotlinxNode): JsonString