Java 使用Jackson提取JSON元数据(原语类型和名称)

Java 使用Jackson提取JSON元数据(原语类型和名称),java,json,jackson,Java,Json,Jackson,我正在写一些需要使用对象的JSON元数据的东西 例如,给定以下示例类: public class MyClassA { @JsonProperty("a") private String a; @JsonProperty("anothername") private Integer b; @JsonProperty("c") private MyClassB c; } public class MyClassB { private I

我正在写一些需要使用对象的JSON元数据的东西

例如,给定以下示例类:

public class MyClassA
{
    @JsonProperty("a")
    private String a;

    @JsonProperty("anothername")
    private Integer b;

    @JsonProperty("c")
    private MyClassB c;
}

public class MyClassB
{
    private Integer z = -1;

    @JsonValue
    public Integer toInteger()
    {
        return z;             
    }
}
我想知道MyClassA映射到以下属性名和JSON基元类型:(a-String,anothername-Number,c-Number),而不必像Jackson在幕后做的那样进行内省


现在还不清楚Jackson下有哪些API可以用来实现这一点。

您需要的是描述JSON的模式。就这一点来说,有一个很好的解释。它可以按如下方式使用:

对象:

class Entity {

    private Long id;
    private List<Profile> profiles;

    // getters/setters
}

class Profile {

    private String name;
    private String value;
    // getters / setters
}
输出:

{
  "type" : "object",
  "properties" : {
    "id" : {
      "type" : "integer"
    },
    "profiles" : {
      "type" : "array",
      "items" : {
        "type" : "object",
        "properties" : {
          "name" : {
            "type" : "string"
          },
          "value" : {
            "type" : "string"
          }
        }
      }
    }
  }
}

来源:

你的意思是什么?是的,这正是我要找的!感谢您的回复,声明您的观点可能重复至少,您可以添加您复制上述示例的页面。。。资料来源:
{
  "type" : "object",
  "properties" : {
    "id" : {
      "type" : "integer"
    },
    "profiles" : {
      "type" : "array",
      "items" : {
        "type" : "object",
        "properties" : {
          "name" : {
            "type" : "string"
          },
          "value" : {
            "type" : "string"
          }
        }
      }
    }
  }
}