2

我正在 quarkus 中构建一个简单的 Jaxrs api。当我调用我的 index 方法时,它看起来像 jackson 用persistent字段序列化对象,它从PanacheEntityBase.

例子:

[
    {
        "persistent": true,
        "id": 1,
        "createdAt": "2019-03-18",
        "updatedAt": "2019-03-18"
    },
    {
        "persistent": true,
        "id": 2,
        "createdAt": "2019-03-18",
        "updatedAt": "2019-03-18"
    }
]

persistent字段不会保存到数据库中,但会显示在响应中。我已经研究过使用@jsonIgnore和杰克逊混合,但我宁愿不必这样做,特别是如果这只是一个配置问题。我很好奇 Panache 是否应该这样做,或者其他人是否有这个问题。

4

2 回答 2

1

当我们使用3-rd party libraries作为返回的数据类型并将其提供给Jackson序列化过程时,就会发生这种情况。PanacheEntity扩展了 PanacheEntityBase,其中包含isPersistent被视为方法JacksonPOJO getter方法。

public boolean isPersistent() {
    return JpaOperations.isPersistent(this);
}

Jackson自动获取 allget*is*方法并尝试将其序列化并包含到 result JSON。没有办法在quarkus级别上配置它。您的解决方案JsonIgnoreMixIn功能是很好的方法。

于 2019-03-18T20:50:15.760 回答
0

使用 Json-B 添加您的实体:

@JsonbTransient
public boolean isPersistent() {
    return super.isPersistent();
}
于 2019-03-22T15:09:43.877 回答