【问题标题】:@JsonInclude not all properties from the object@JsonInclude 不是对象的所有属性
【发布时间】:2017-04-22 01:59:55
【问题描述】:

我在一个类中有这个属性:

@ManyToOne
@JoinColumn(name = "id_object", nullable = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public Object someObject;

这个对象可以为null,但如果不是,我只想带someObject的一个字段,而不是它的所有字段。

我不能在 Object 中使用 JsonIgnore,因为在其他端点中我想带入该对象的所有字段。

我可以在@JsonInclude 中传递任何参数以在 json 中仅返回一个或两个 Object 字段吗?

【问题讨论】:

    标签: java spring spring-restcontroller


    【解决方案1】:

    也许使用 mixins 是一种合适的方法。

    这将允许您在不同条件下返回同一对象的不同参数

    【讨论】:

    猜你喜欢
    • 2017-06-08
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    相关资源
    最近更新 更多