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 (将#修改为@)