Class EntityModule

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    void
    setupModule(com.fasterxml.jackson.databind.Module.SetupContext context)
     
    com.fasterxml.jackson.core.Version
     

    Methods inherited from class com.fasterxml.jackson.databind.Module

    getDependencies, getTypeId

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EntityModule

      public EntityModule()
  • Method Details

    • getModuleName

      public String getModuleName()
      Specified by:
      getModuleName in class com.fasterxml.jackson.databind.Module
    • version

      public com.fasterxml.jackson.core.Version version()
      Specified by:
      version in interface com.fasterxml.jackson.core.Versioned
      Specified by:
      version in class com.fasterxml.jackson.databind.Module
    • setupModule

      public void setupModule(com.fasterxml.jackson.databind.Module.SetupContext context)
      Specified by:
      setupModule in class com.fasterxml.jackson.databind.Module