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 fields 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 were considered
as meta-data and were prefixed with _, properties from self object were serialized at the same leve "as is".
All Jackson annotations on the self object was read and used.
This serializer avoid Jackson problems 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 TypeMethodDescriptionvoidsetupModule(com.fasterxml.jackson.databind.Module.SetupContext context) com.fasterxml.jackson.core.Versionversion()Methods inherited from class com.fasterxml.jackson.databind.Module
getDependencies, getTypeId
-
Constructor Details
-
EntityModule
public EntityModule()
-
-
Method Details
-
getModuleName
- Specified by:
getModuleNamein classcom.fasterxml.jackson.databind.Module
-
version
public com.fasterxml.jackson.core.Version version()- Specified by:
versionin interfacecom.fasterxml.jackson.core.Versioned- Specified by:
versionin classcom.fasterxml.jackson.databind.Module
-
setupModule
public void setupModule(com.fasterxml.jackson.databind.Module.SetupContext context) - Specified by:
setupModulein classcom.fasterxml.jackson.databind.Module
-