API
Everything a caller touches: the two operations of JsonMapper, the callbacks they take, and the annotations and traits the mapper reads.
JsonMapper
Two operations
Both take the value's ResolvedClass from TypeResolver.resolve and an optional EntityGraph (null for none).
- new JsonMapper(validator, loader, inject)
- Holds what the application provides. The defaults are no validator, EntityLoader.none and Inject.constructor.
- mapper.serialize(instance, resolvedClass, graph, projection): String
- The object as compact JSON text.
- mapper.deserialize(jsonNode, instance, resolvedClass, graph): Any
- Merges the JSON into instance and returns it; throws ErrorRequestException with every invalid value and then writes nothing.
- mapper.prepare(jsonNode, entity, resolvedClass, graph): PreparedChange[T]
- Defers the merge: getEntity() gives the entity, applyChanges() merges once, later.
- JsonMapper.schema(classOf[T]): JsonSchema
- The JSON Schema of a class; JsonSchema.encode(schema) writes it as text.
- JsonParser.parse(json: String): JsonNode
- Parses text into the mapper's JSON nodes.
- JsonGenerator.generate(node: JsonNode): String
- Writes nodes back to text.
Callbacks
What the application provides
The mapper has no container of its own. Everything it needs from the application arrives as a function or a trait.
- inject: [T] => Class[T] => T
- Creates rules and other helpers; wire it to your DI container.
- EntityLoader.load(id: UUID, clazz: Class[?]): Any
- Resolves a reference by ID and is the authorization boundary; null rejects the ID as invalid input.
- jakarta.validation.Validator
- Checks each value before it is set.
Model
Annotations and traits
What a class declares to take part.
- Includes a field or getter; an optional value renames it.
- A map collecting undeclared fields.
- (transitive)
- transitive = true includes the property regardless of the graph.
- (classOf[C])
- Writes and reads the value through a converter.
- DTO
- Marks an object the mapper descends into.
- EntityProvider
- id and version; enables graphs and ID matching.
- SchemaProvider[S] · EntitySchema[T]
- Lists the exposed properties and their rules.