Skip to content
Anjunar/ DOCS

JSON Mapper

JSON for applications with a domain model. Deserialization merges into the objects you already have, so an update touches what changed and keeps identity, references and relations intact.

1.1.5Current release
JVMRuns on
Scala 3.3Language version
MITLicense

Installation

One artifact. It brings scala-universe along, which resolves the types the mapper works with.

sbt
libraryDependencies += "com.anjunar" %% "json-mapper" % "1.1.5"

Merge, don't replace

The target already exists, loaded from the database or held in memory. The JSON changes two properties; everything else on the object stays.

scala
import com.anjunar.json.mapper.JsonMapper import com.anjunar.json.mapper.intermediate.JsonParser import com.anjunar.scala.universe.TypeResolver val user = loadUser() // an existing UserDto val address = user.address JsonMapper.deserialize( JsonParser.parse("""{"name": "Grace", "address": {"city": "Hamburg"}}"""), user, TypeResolver.resolve(classOf[UserDto]), null, loader, inject, validator ) println(user.name) // Grace println(user.address eq address) // true: the same address, now in Hamburg
01 / Merge

In place, not new

Nested objects and collections are updated where they are. Elements keep their identity by ID.

02 / Rules

The model decides what is visible

A schema per entity lists its properties; a rule per property decides who may read and who may write it.

03 / Integrity

Validated, referenced, in sync

Bean Validation per property, references loaded by ID, and both sides of a JPA relation kept consistent.

Contents

From a DTO to an entity graph

The basics work with plain DTOs. The domain pages add schemas, graphs and references for JPA entities.