2

I'm trying to setup Javers using a MongoDB repository. I'm using version 2.9.1 for both javers-core and javers-persistence-mongo.

However, when I try to commit an entity with a Boolean field, the following exception is thrown:

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:?]

Looking into the private static Object fromJsonElement(JsonElement jsonElement) method in javers-persistence-mongo-2.9.1/DocumentConverter, there are only conversion methods for the JsonPrimitives String and Number (not Boolean).

Am I missing some configuration here?

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;
  }
4

1 回答 1

0

这是 2.9.1 中引入的错误。观看此问题中的错误修复进度https://github.com/javers/javers/issues/494

(已编辑)在 2.9.2 中修复

于 2017-01-23T20:42:32.993 回答