public abstract class MappingDocumentation extends Object
JaversBuilder methods:
JaversBuilder.registerEntity(Class)
JaversBuilder.registerValueObject(Class)
JaversBuilder.registerValue(Class)
Entity has exactly the same semantic like DDD Entity or JPA Entity.
Usually, each entity instance represents concrete physical object.
Entity has a list of mutable properties and its own identity hold in id property.
For example Entities are: Person, Company.
ValueObject is similar to DDD ValueObject and JPA Embeddable.
It's a complex value holder with a list of mutable properties but no unique identifier.
In strict DDD approach, Value Objects can't exists independently and have to be bound do Entity instances
(as a part of an Aggregate). Javers is not such radical and supports both embedded and dangling Value Objects.
For example Value Objects are: Address, Point
ValueType is a simple (scalar) value holder.
Two Values are compared using equals() so
its highly important to implement it properly by comparing underlying state.
For example Values are: BigDecimal, LocalDate
For Values it's advisable to customize JSON serialization by implementing Type Adapters, see JsonConverter.
ObjectGraphBuilder asks TypeMapper about JaversType of Person.class.
TypeMapper does the following
JaversBuilder
as one of Entitiy, Value Object or Value. If so, answer is easy.
Then TypeMapper tries to find so called Prototype—nearest class or interface that is already mapped and is assignable from Person.class.
So as You can see, it's easy to map whole bunch of classes with common superclass or interface with one call to JaversBuilder.
Just register those high level concepts.
When Prototype is not found, Javers tries to infer Type by looking for well known JPA annotations: Entity
and Id.
If found, class would be mapped as Entity, otherwise as ValueObject.
JaversBuilder configuration by taking advantage of type inferring policy.
For Values, remember about implementing equals() and consider implementing JSON type adapters.Copyright © 2014. All rights reserved.