Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueObject deserialization exception #206

Closed
floresek opened this issue Sep 24, 2015 · 12 comments
Closed

ValueObject deserialization exception #206

floresek opened this issue Sep 24, 2015 · 12 comments
Assignees

Comments

@floresek
Copy link

Hi,

Suppose two classes:

class Master {
    @Id
    String id;
    Detail detail;

    public Master(String id) {
        this.id = id;
    }

}

@ValueObject
class Detail {
    String data;

    public Detail(String data) {
        this.data = data;
    }
}

If I provide Detail object before initil commit, everything is OK:

        Master master = new Master("1");
        master.detail = new Detail("details");
        javers.commit("anonymous", master);

If I provide Detail object before after initial commit, everything is OK:

        Master master = new Master("1");
        javers.commit("anonymous", master);
        master.detail = new Detail("details");
        javers.commit("anonymous", master);
        List<Change> changes = javers
                .findChanges(QueryBuilder.byInstanceId("1", Master.class)
                        .withNewObjectChanges(true)
                        .build());

I got deserialization error during findChanges operation (or third commit attempt):

java.lang.NullPointerException
    at org.javers.core.json.typeadapter.commit.GlobalIdTypeAdapter.parseClass(GlobalIdTypeAdapter.java:117)
    at org.javers.core.json.typeadapter.commit.GlobalIdTypeAdapter.parseUnboundedValueObject(GlobalIdTypeAdapter.java:51)
    at org.javers.core.json.typeadapter.commit.GlobalIdTypeAdapter.fromJson(GlobalIdTypeAdapter.java:46)
    at org.javers.core.json.typeadapter.commit.GlobalIdTypeAdapter.fromJson(GlobalIdTypeAdapter.java:18)
    at org.javers.core.json.JsonConverterBuilder$2.deserialize(JsonConverterBuilder.java:144)
    at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
    at com.google.gson.Gson.fromJson(Gson.java:810)
    at com.google.gson.Gson.fromJson(Gson.java:875)
    at com.google.gson.Gson$1.deserialize(Gson.java:128)
    at org.javers.core.json.typeadapter.commit.GlobalIdTypeAdapter.parseValueObjectId(GlobalIdTypeAdapter.java:58)
    at org.javers.core.json.typeadapter.commit.GlobalIdTypeAdapter.fromJson(GlobalIdTypeAdapter.java:44)
    at org.javers.core.json.typeadapter.commit.GlobalIdTypeAdapter.fromJson(GlobalIdTypeAdapter.java:18)
    at org.javers.core.json.JsonConverterBuilder$2.deserialize(JsonConverterBuilder.java:144)
    at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
    at com.google.gson.Gson.fromJson(Gson.java:810)
    at com.google.gson.Gson.fromJson(Gson.java:875)
    at org.javers.core.json.JsonConverter.fromJson(JsonConverter.java:85)
    at org.javers.core.json.JsonConverter$1.deserialize(JsonConverter.java:60)
    at org.javers.core.json.typeadapter.commit.CdoSnapshotStateDeserializer.decodePropertyValue(CdoSnapshotStateDeserializer.java:48)
    at org.javers.core.json.typeadapter.commit.CdoSnapshotStateDeserializer.deserialize(CdoSnapshotStateDeserializer.java:39)
    at org.javers.core.json.JsonConverter.snapshotStateFromJson(JsonConverter.java:107)
    at org.javers.repository.sql.finders.CdoSnapshotObjectMapper.createObject(CdoSnapshotObjectMapper.java:45)
    at org.javers.repository.sql.finders.CdoSnapshotObjectMapper.createObject(CdoSnapshotObjectMapper.java:24)
    at org.polyjdbc.core.query.TransactionalQueryRunner.queryCollection(TransactionalQueryRunner.java:88)
    at org.polyjdbc.core.query.TransactionalQueryRunner.queryList(TransactionalQueryRunner.java:76)
    at org.javers.repository.sql.finders.CdoSnapshotFinder.queryForCdoSnapshots(CdoSnapshotFinder.java:97)
    at org.javers.repository.sql.finders.CdoSnapshotFinder.getStateHistory(CdoSnapshotFinder.java:74)
    at org.javers.repository.sql.JaversSqlRepository.getStateHistory(JaversSqlRepository.java:76)
    at org.javers.repository.api.JaversExtendedRepository.getStateHistory(JaversExtendedRepository.java:76)
    at org.javers.repository.api.JaversExtendedRepository.getChangeHistory(JaversExtendedRepository.java:55)
    at org.javers.repository.jql.QueryRunner.queryForChanges(QueryRunner.java:74)
    at org.javers.core.JaversCore.findChanges(JaversCore.java:114)
    at javers.JaversTest.createTestMaster(JaversTest.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

In first (working) scenario master is serialized as:

{
  "id": "1",
  "detail": {
    "valueObject": "javers.Detail",
    "ownerId": {
      "entity": "javers.Master",
      "cdoId": "1"
    },
    "fragment": "detail"
  }
}

In second scenario master is serialized as:

{
  "id": "1",
  "detail": {
    "valueObject": "javers.Detail",
    "ownerId": {
      "instance": {
        "entity": "javers.Master",
        "cdoId": "1"
      },
      "primaryKey": {
        "reference": 4100
      }
    },
    "fragment": "detail"
  }
}

Could you fix this bug, please?

Cheers
Mariusz

@bartoszwalacik
Copy link
Member

Thanks for reporting, will check it

@bartoszwalacik bartoszwalacik self-assigned this Sep 24, 2015
@bartoszwalacik
Copy link
Member

ok, I can reproduce it on H2 repository

@floresek
Copy link
Author

I hope you deal with it quickly ;)

@floresek
Copy link
Author

The problem (with deserialization) occurs also when updating entity with previously (initially) set reference ValueObjects.

class Master {
    @Id
    String id;
    Detail detail;
    String data;

    List<Detail> list = new ArrayList<>();
    Set<Detail> set = new HashSet<>();
    Map<String, Detail> map = new HashMap<>();
    Detail[] array;

    public Master(String id) {
        this.id = id;
    }
}

@ValueObject
class Detail {
    String data;

    public Detail(String data) {
        this.data = data;
    }
}

        ...
        Master master = new Master("2");
        master.data = "data";
        master.detail = new Detail("details");
        javers.commit("anonymous", master);
        master.data = "data2";
        javers.commit("anonymous", master);
        List<Change> changes = javers
                .findChanges(QueryBuilder.byInstanceId("2", Master.class)
                        .withNewObjectChanges(true)
                        .build());
        String changeLog = javers.processChangeList(changes, getChangeLogger());
        ...

During second commit the structure of previously saved json is changed from ownerId:entity to ownerId:instance/primaryKey and while deserialization exception occurs.

Similar problem (with deserialization) occurs when using list/set/map/array of ValueObjects.

@bartoszwalacik
Copy link
Member

bugs have high priority, expect a fix after weekend

@floresek
Copy link
Author

thanks ;)

@floresek
Copy link
Author

Przepraszam, że Cię nękam issues'ami, ale spodobał mi się javers i chciałem go nieco zewaluować ;)

@bartoszwalacik
Copy link
Member

Miło, teraz jestem na wypadzie w Beskid Sądecki wiec ten bug musi poczekac do poniedzialku. Btw w javersie jest duże zapotrzebowanie na kontrybucje...

@floresek
Copy link
Author

OK, jak się wystarczająco wgryzę ;)

@bartoszwalacik
Copy link
Member

Found a bug in serializing ValueObject references in sql repository. In some cases JSON is malformed

@bartoszwalacik
Copy link
Member

fixed in v 1.3.10

@floresek
Copy link
Author

floresek commented Oct 1, 2015

Excellent, thanks ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants