我正在尝试使用MongoDB存储库设置Javers。我对javers-core
和javers-persistence-mongo
使用版本2.9.1。
但是,当我尝试使用布尔字段提交实体时,会抛出以下异常:
java.lang.IllegalArgumentException: unsupported JsonElement type - JsonPrimitive
at org.javers.repository.mongo.DocumentConverter.fromJsonElement(DocumentConverter.java:71) ~[javers-persistence-mongo-2.9.1.jar:?]
at org.javers.repository.mongo.DocumentConverter.toDocument(DocumentConverter.java:20) ~[javers-persistence-mongo-2.9.1.jar:?]
at org.javers.repository.mongo.DocumentConverter.fromJsonElement(DocumentConverter.java:39) ~[javers-persistence-mongo-2.9.1.jar:?]
at org.javers.repository.mongo.DocumentConverter.toDocument(DocumentConverter.java:20) ~[javers-persistence-mongo-2.9.1.jar:?]
at org.javers.repository.mongo.MongoRepository.writeToDBObject(MongoRepository.java:200) ~[javers-persistence-mongo-2.9.1.jar:?]
at org.javers.repository.mongo.MongoRepository.persistSnapshots(MongoRepository.java:217) ~[javers-persistence-mongo-2.9.1.jar:?]
at org.javers.repository.mongo.MongoRepository.persist(MongoRepository.java:74) ~[javers-persistence-mongo-2.9.1.jar:?]
at org.javers.repository.api.JaversExtendedRepository.persist(JaversExtendedRepository.java:109) ~[javers-core-2.9.1.jar:?]
at org.javers.core.JaversCore.commit(JaversCore.java:83) ~[javers-core-2.9.1.jar:?]
at org.javers.core.JaversCore.commit(JaversCore.java:65) ~[javers-core-2.9.1.jar:?]
查看private static Object fromJsonElement(JsonElement jsonElement)
中的javers-persistence-mongo-2.9.1/DocumentConverter
方法,只有JsonPrimitives String和Number(非布尔值)的转换方法。
我在这里错过了一些配置吗?
MWE:
public static void main(final String[] args) {
final TestEntity testEntity = new TestEntity();
testEntity.id = 12345L;
testEntity.testBoolean = true;
final MongoClient mongoClient = new MongoClient(...);
final Javers javers = JaversBuilder.javers()
.registerJaversRepository(new MongoRepository(mongoClient.getDatabase(...))).build();
javers.commit("testAuthor", testEntity); // Throws IllegalArgumentException
}
@Entity
static class TestEntity {
@Id
Long id;
Boolean testBoolean;
}
答案 0 :(得分:0)
这是2.9.1中引入的错误。观看此问题https://github.com/javers/javers/issues/494
中修复进度的错误(编辑)的 修正于2.9.2