微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jsonschema2pojo-排除toString中的某些字段

如何解决jsonschema2pojo-排除toString中的某些字段

我使用jsonschema2pojo通过maven插件生成POJO。

架构JSON:

{
  "$id": "https://example.com/address.schema.json","$schema": "http://json-schema.org/draft-07/schema#","title": "Person Type","description": "Description of a Person","type": "object","additionalProperties" : false,"includeConstructors" : true,"properties": {
      "name" : {
        "type" : "string"
      },"age" : {
        "type" : "string"
      },"gender" : {
        "type" : "string"
     }
   }
 }

生成toString()

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(Person.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
    sb.append("name");
    sb.append('=');
    sb.append(((this.name == null)?"<null>":this.name));
    sb.append(',');
    sb.append("age");
    sb.append('=');
    sb.append(((this.age == null)?"<null>":this.age));
    sb.append(',');
    sb.append("gender");
    sb.append('=');
    sb.append(((this.gender == null)?"<null>":this.gender));
    sb.append(',');
    if (sb.charat((sb.length()- 1)) == ',') {
        sb.setCharat((sb.length()- 1),']');
    } else {
        sb.append(']');
    }
    return sb.toString();
}

如上所述,所有属性都包含在生成的toString()方法中。我想知道如何排除特定属性

我知道在插件配置中使用<toStringExcludes>会排除toString()中的属性。这种方法的问题是:在属性名称相同的所有类型中,此方法都忽略了toString()方法中的字段。就我而言,我只需要排除一种类型的属性,同时仍然允许其他类型在toString中显示属性

Maven配置:

<toStringExcludes>gender</toStringExcludes>

如何仅以一种类型(例如:人)在toString()中排除特定属性(例如:性别)?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。