【问题标题】:Error when using with annotation Mixins with ObjectMapper使用带有 ObjectMapper 的注释 Mixins 时出错
【发布时间】:2013-01-31 13:08:30
【问题描述】:

我正在尝试使用以下代码为我的一个 POJO 创建一个 mixin:

interface CustomerStatsIgnoreMixIn {
    @JsonIgnoreProperties({"ref"});
}

public class CustomerStatsJob extends Job {
    private void updateCustomer(Customer customer) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.getSerializationConfig().addMixInAnnotations(Customer.class,
                CustomerStatsIgnoreMixIn.class);
    }
}

我在 @JsonIgnoreProperties({"ref"}); 行的 Eclipse 中收到以下错误

此行有多个标记 - 语法错误,插入“枚举标识符”以完成 EnumHeaderName - 语法错误,插入“EnumBody”来完成EnumDeclaration

我确定这很愚蠢,但你知道问题是什么吗?

【问题讨论】:

    标签: java jackson mixins


    【解决方案1】:

    JsonIgnoreProperties 注解是一个类型注解...它应该在接口定义行的正上方,而不是在接口的主体中。

    喜欢:

    @JsonIgnoreProperties({"ref"});
    interface CustomerSTatesIgnoreMixin {
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-11-08
      • 2015-10-19
      • 1970-01-01
      • 2023-03-14
      • 2023-03-10
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      • 2015-05-07
      相关资源
      最近更新 更多