Envers fails when a field is edited and another field is lazy (and not loaded)

I have a field such as:

    @Column(name = "data")
    @JdbcTypeCode(SqlTypes.JSON)
    @Basic(fetch = FetchType.LAZY)
    @JsonIgnore
    public Map<String, Object> data;

and the class is @Audited(withModifiedFlag = true)

When i try to edit another field during the transaction (such as myEntity.someString = "new value") and the data field is not loaded/retrieved, i get an error such as:

Caused by: java.lang.IllegalArgumentException: Could not serialize object of java type: JsonJavaType(java.util.Map<java.lang.String, java.lang.Object>)
    at org.hibernate.type.format.jackson.JacksonJsonFormatMapper.toString(JacksonJsonFormatMapper.java:56)
    at org.hibernate.type.descriptor.jdbc.JsonJdbcType.toString(JsonJdbcType.java:109)
    at org.hibernate.dialect.AbstractPostgreSQLJsonPGObjectType.access$000(AbstractPostgreSQLJsonPGObjectType.java:29)
    at org.hibernate.dialect.AbstractPostgreSQLJsonPGObjectType$1.doBind(AbstractPostgreSQLJsonPGObjectType.java:48)
    at org.hibernate.type.descriptor.jdbc.BasicBinder.bind(BasicBinder.java:61)
    at org.hibernate.engine.jdbc.mutation.internal.JdbcValueBindingsImpl.lambda$beforeStatement$0(JdbcValueBindingsImpl.java:87)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at org.hibernate.engine.jdbc.mutation.spi.BindingGroup.forEachBinding(BindingGroup.java:51)
    at org.hibernate.engine.jdbc.mutation.internal.JdbcValueBindingsImpl.beforeStatement(JdbcValueBindingsImpl.java:85)
    at org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.performNonBatchedMutation(AbstractMutationExecutor.java:130)
    at org.hibernate.engine.jdbc.mutation.internal.MutationExecutorSingleNonBatched.performNonBatchedOperations(MutationExecutorSingleNonBatched.java:55)
    at org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.execute(AbstractMutationExecutor.java:55)
    at org.hibernate.persister.entity.mutation.InsertCoordinatorStandard.doStaticInserts(InsertCoordinatorStandard.java:194)
    at org.hibernate.persister.entity.mutation.InsertCoordinatorStandard.coordinateInsert(InsertCoordinatorStandard.java:132)
    at org.hibernate.persister.entity.mutation.InsertCoordinatorStandard.insert(InsertCoordinatorStandard.java:104)
    at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:110)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:632)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:499)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:371)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:41)
    at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
    at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1425)
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1411)
    at org.hibernate.envers.internal.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:178)
    at org.hibernate.envers.internal.synchronization.AuditProcessManager$1.doBeforeTransactionCompletion(AuditProcessManager.java:47)
    at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:1014)
    ... 40 more
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Incompatible types: declared root type ([map type; class java.util.Map, [simple type, class java.lang.String] -> [simple type, class java.lang.Object]]) vs `org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1`

If i remove @Basic(fetch = FetchType.LAZY) then everything works

If i step through the code execution, i can see that the entity is created, but is seems like it tries to serialize "<lazy>" and fails

I have other fields that are NOT Map but are LAZY, and they do not cause an issue

and if i set @AuditOverride(isAudited = false) on the field and again everything works

And finally if i edit the lazy loaded data field, it correctly generates envers history.
The above error only seems to happen when you edit another field (such as a typical String field) and the lazy data field is NOT loaded.

Hi @StephenOTT, this sounds like a bug. Please create an issue in the issue tracker with a test case that reproduces the issue.

Note, however, that hibernate envers is not receiving a lot of attention at the moment and it might be a long time before anyone can look at that issue.