1

I have a problem customizing the reperesentation of ListChanges in javers:

Given two structures:

@Entity
public class User {

   private Long id;
   ....

   @OneToMany
   private List<Authorisation> authorisations;
}

and

@Entity
public class Authorisation {

    @Id
    private Long id;
    ...

    private String name;
    private String scope;
    private String asset;

    @Override
    public String toString() {
       return name + " " + scope + ": " + asset;
    }
}

i want to display ListChanges of Authorisations in a more human readable form when querying for a user who's authorisations changed. When im querying now:

 QueryBuilder jqlQuery = QueryBuilder.byInstance(repo.findByUserId(userId));
 List<Change> changes = javers.findChanges(jqlQuery.withChildValueObjects().build());
 ....
 javers.getJsonConverter().toJson(changes.get(0))
 // or
 changes.get(0).toString()

i get results like this for the ListChanges:

   {
    "changeType": "ListChange",
    ...
    "property": "authorisations",
    "propertyChangeType": "PROPERTY_VALUE_CHANGED",
    "elementChanges": [
      {
        "elementChangeType": "ValueAdded",
        "index": 0,
        "value": {
          "entity": "....Authorisation",
          "cdoId": 1
        }
      }
    ]
   }

or

ListChange{ 'authorisations' collection changes :
0. '...Authorisation/1' added }

i now want to render the Authorisation in a more human readable form like using the toString() method from Authorisation so that the output looks like

ListChange{ 'authorisations' collection changes :
0. '...Authorisation/abc def ghi' added }

I hope anyone has an idea, so thanks in advance.

elank
  • 11
  • 1
  • Did you tried https://javers.org/documentation/repository-examples/#change-log – Bartek Walacik Mar 18 '20 at 18:36
  • Thanks for your quick reply, i tried this solution as well, but i can't access the nested values there. I found out, that a very dirty workaround could be a custom Type Adapter and register them with `registerValueTypeAdapter`: `class AuthorisationTypeAdapter extends BasicStringTypeAdapter` but this is very inconvenient and not fault tolerant. The bad thing on this solution is, that i have to implement the desialize funtion as well (from String...). – elank Mar 20 '20 at 13:32

0 Answers0