Json序列化接近prettyPrint()方法输出中显示的内容

时间:2018-09-05 19:04:37

标签: java diff javers

我正在尝试使用javers的json转换器将diff数据导出到我的前端,但是我无法获得Diff.prettyPrint()返回中包含的相同内容,其中包含从“ x”到“ 'y'“ ... json输出包含一些无用的数据,甚至显示的数据顺序也各不相同。

我的实际代码:

Diff diff = javers.compare(projOriginal,projNew);
String diffJson = javers.getJsonConverter().toJson(diff);

相同diff变量的输出: PrettyPrint:

* object removed: myproj.domain.entity.projeto.Requisito/5
* new object: myproj.domain.entity.projeto.Requisito/7
* changes on myproj.domain.entity.projeto.Requisito/7 :
  - 'descricao' changed from '' to 'requisito 1'
  - 'id' changed from '' to '7'
* changes on myproj.domain.entity.projeto.Risco/6 :
  - 'fatorPriorizacao' changed from '0.10' to '0.100000000000000006'
* new object: myproj.domain.entity.projeto.Requisito/8
* changes on myproj.domain.entity.projeto.Requisito/8 :
  - 'descricao' changed from '' to 'lionel messi'
  - 'id' changed from '' to '8'
* changes on myproj.domain.entity.usuario.Usuario/1 :
  - 'ultimoAcesso' changed from '29 ago 2018, 14:50:28' to '05 set 2018, 14:35:29'
* changes on myproj.domain.entity.projeto.dto.ProjetoDTO/2 :
  - 'avisoComplexidade' changed from 'true' to 'false'
  - 'requisitosList' collection changes :
    0. '...Requisito/5' changed to '...Requisito/8'
    1. '...Requisito/7' added

JsonConverter:

{
  "changes": [
    {
      "changeType": "NewObject",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.Requisito",
        "cdoId": 8
      }
    },
    {
      "changeType": "NewObject",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.Requisito",
        "cdoId": 7
      }
    },
    {
      "changeType": "ObjectRemoved",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.Requisito",
        "cdoId": 5
      }
    },
    {
      "changeType": "ValueChange",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.Requisito",
        "cdoId": 7
      },
      "property": "descricao",
      "left": null,
      "right": "requisito 1"
    },
    {
      "changeType": "ValueChange",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.Requisito",
        "cdoId": 7
      },
      "property": "id",
      "left": null,
      "right": 7
    },
    {
      "changeType": "ValueChange",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.Requisito",
        "cdoId": 8
      },
      "property": "descricao",
      "left": null,
      "right": "lionel messi"
    },
    {
      "changeType": "ValueChange",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.Requisito",
        "cdoId": 8
      },
      "property": "id",
      "left": null,
      "right": 8
    },
    {
      "changeType": "ValueChange",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.dto.ProjetoDTO",
        "cdoId": 2
      },
      "property": "avisoComplexidade",
      "left": true,
      "right": false
    },
    {
      "changeType": "ListChange",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.dto.ProjetoDTO",
        "cdoId": 2
      },
      "property": "requisitosList",
      "elementChanges": [
        {
          "elementChangeType": "ElementValueChange",
          "index": 0,
          "leftValue": {
            "entity": "myproj.domain.entity.projeto.Requisito",
            "cdoId": 5
          },
          "rightValue": {
            "entity": "myproj.domain.entity.projeto.Requisito",
            "cdoId": 8
          }
        },
        {
          "elementChangeType": "ValueAdded",
          "index": 1,
          "value": {
            "entity": "myproj.domain.entity.projeto.Requisito",
            "cdoId": 7
          }
        }
      ]
    },
    {
      "changeType": "ValueChange",
      "globalId": {
        "entity": "myproj.domain.entity.projeto.Risco",
        "cdoId": 6
      },
      "property": "fatorPriorizacao",
      "left": 0.10,
      "right": 0.100000000000000006
    },
    {
      "changeType": "ValueChange",
      "globalId": {
        "entity": "myproj.domain.entity.usuario.Usuario",
        "cdoId": 1
      },
      "property": "ultimoAcesso",
      "left": "2018-08-29T14:50:28.837",
      "right": "2018-09-05T14:35:29.928"
    }
  ]
}

另一个巨大的问题是我看不到对象的附着路径。可以说,我确实在“ projetoDTO.masterUser”中有一个用户附加到我的图形,在“ projetoDTO.requisito”中有其他用户。 userThatManagesIt”:如果发生更改,我将永远不会知道该用户来自何处,只是该用户已被修改。 有困难吗? Ty

修改

另一件事是,我知道一个对象已被删除...就是这样!使用Long as @Id我不知道删除了什么,因为“ 1”与用户无关。有什么想法吗?也许可以使用withDeletedObjects(true)来获取新对象?

0 个答案:

没有答案