Javers MongoRepository 为 Boolean JsonPrimitive 抛出 IllegalArgumentException
Javers MongoRepository throwing IllegalArgumentException for Boolean JsonPrimitive
我正在尝试使用 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:?]
查看javers-persistence-mongo-2.9.1/DocumentConverter
中的private static Object fromJsonElement(JsonElement jsonElement)
方法,只有JsonPrimitives String和Number(不是Boolean)的转换方法。
我是不是遗漏了一些配置?
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;
}
这是 2.9.1 中引入的错误。观看此问题的错误修复进度 https://github.com/javers/javers/issues/494
(已编辑)
已在 2.9.2
中修复
我正在尝试使用 MongoDB 存储库设置 Javers。 javers-core
和 javers-persistence-mongo
.
但是,当我尝试提交具有布尔字段的实体时,抛出以下异常:
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:?]
查看javers-persistence-mongo-2.9.1/DocumentConverter
中的private static Object fromJsonElement(JsonElement jsonElement)
方法,只有JsonPrimitives String和Number(不是Boolean)的转换方法。
我是不是遗漏了一些配置?
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;
}
这是 2.9.1 中引入的错误。观看此问题的错误修复进度 https://github.com/javers/javers/issues/494
(已编辑) 已在 2.9.2
中修复