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

Javers Diff - Converting InitialValueChange with JsonConverter throws error #1092

Closed
maffinre opened this issue May 19, 2021 · 4 comments
Closed

Comments

@maffinre
Copy link

maffinre commented May 19, 2021

Hello Javers-Team,
I found a bug which affects the JsonConverter.
An error is thrown in the JsonConverter when the JSON includes an InitialValueChange.

Example:
I created a Diff of two objects. One has a new child with initial values. This diff is converted to JSON with:

Javers javers = JaversBuilder.javers().withTerminalChanges(false).build();
Diff diff = javers.compare(fooOldRevision, fooCurrent);
javers.getJsonConverter().toJson(diff);

The output-JSON of this is:

{
  "changes": [
    {
      "changeType": "NewObject",
      "globalId": {
        "entity": "cms.domain.Bar",
        "cdoId": "58e90e85-e7c6-47f1-96b2-e71b7d936132"
      }
    },
    {
      "changeType": "InitialValueChange",
      "globalId": {
        "entity": "cms.domain.Bar",
        "cdoId": "58e90e85-e7c6-47f1-96b2-e71b7d936132"
      },
      "property": "id",
      "propertyChangeType": "PROPERTY_VALUE_CHANGED"
    }
  ]
}

If I now take this JSON and put it in the method

Diff diff = javers.getJsonConverter().fromJson(changes, Diff.class);

to convert it to a Diff again, an error is thrown: MALFORMED_CHANGE_TYPE_FIELD: no such Change type - 'InitialChange'

This error seems to be thrown in the ChangeTypeAdapter.class as the InitialValueChange.class is not part of the constructor of this class.

Thank you for your help!

@bartoszwalacik
Copy link
Member

Hi, thanks for reporting, consider contributing a PR with the fix

@maffinre
Copy link
Author

I added the init but it was not working after that as well.
After adding the init, it was possible to convert the JSON into a Diff, but all the values of the initialValueChange were null.
It seems that some kind of initialization is still missing after this.
Could you please look into this as I cannot find the problem?

@bartoszwalacik
Copy link
Member

bartoszwalacik commented May 21, 2021

The problem is that there is no de-serialization code in javers for that types: InitialValueChange and TerminalValueChange. See org.javers.core.json.typeadapter.change.ValueChangeTypeAdapter. I will fix it

@bartoszwalacik
Copy link
Member

fixed in 6.1.1

lucas-prestes pushed a commit to lucas-prestes/javers that referenced this issue Jun 19, 2021
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