java.lang.Object
com.fasterxml.jackson.databind.Module
fr.ght1pc9kc.entity.jackson.EntityModule
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned
public class EntityModule
extends com.fasterxml.jackson.databind.Module
The Jackson module managing
Entity
type object
Deserialization
Manage the Entity
deserialization.
All field starting with "_
" are considered as meta data and will be used for Entity,
all other fields are considered to belong to the self object
Serialization
Entity.self()
was serialized as unwrapped object. All properties from Entity was considered
as meta data and was prefixed with _
, properties from self object was serialized at the same leve "as is".
All Jackson annotations on the self
object was read and used.
This serializer avoid Jackson problem of using JsonTypeInfo
inside an
object annotated with JsonUnwrapped
The entity :
Entity.<Saber>identify(new LightSaber(Color.GREEN, 1))
.meta(createdAt, Instant.parse("2024-01-20T15:06:42.546Z"))
.meta(createdBy, "okenobi")
.withId("LIGHTSABER");
become
{ "_id": "LIGHTSABER", "_createdAt": "2024-01-20T15:06:42.546Z", "_createdBy": "okenobi", "@type": "LIGHT", "blade": 1, "color": "GREEN" }
if Saber interface declared as
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "@type")
@JsonSubTypes({
@JsonSubTypes.Type(value = LightSaber.class, name = "LIGHT"),
@JsonSubTypes.Type(value = DarkSaber.class, name = "DARK")
})
public sealed interface Saber permits DarkSaber, LightSaber {
Color color();
}
-
Nested Class Summary
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.Module
com.fasterxml.jackson.databind.Module.SetupContext
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
setupModule
(com.fasterxml.jackson.databind.Module.SetupContext context) com.fasterxml.jackson.core.Version
version()
Methods inherited from class com.fasterxml.jackson.databind.Module
getDependencies, getTypeId
-
Constructor Details
-
EntityModule
public EntityModule()
-
-
Method Details
-
getModuleName
- Specified by:
getModuleName
in classcom.fasterxml.jackson.databind.Module
-
version
public com.fasterxml.jackson.core.Version version()- Specified by:
version
in interfacecom.fasterxml.jackson.core.Versioned
- Specified by:
version
in classcom.fasterxml.jackson.databind.Module
-
setupModule
public void setupModule(com.fasterxml.jackson.databind.Module.SetupContext context) - Specified by:
setupModule
in classcom.fasterxml.jackson.databind.Module
-