【问题标题】:FasterXML schema generation for Maps and Object references地图和对象引用的更快 XML 模式生成
【发布时间】:2014-02-07 17:36:48
【问题描述】:

我在使用 FasterXML 生成 JSON 架构文件时遇到问题。 文件输出只是显示

  • object 输入 Map<String, String>
  • null 输入 OtherBean

{ “类型”:“对象”, “特性”: { “beanId”:{ “类型”:“整数” }, “豆名”:{ “类型”:“字符串” }, “豆地图”:{ “类型”:“对象” }, “其他豆”:空 } }

我的架构生成类

import java.io.File;
import java.io.IOException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsonschema.JsonSchema;

public class Main {

    public static void main(String[] args) throws IOException {

        ObjectMapper MAPPER = new ObjectMapper();

        JsonSchema jsonSchema = MAPPER.generateJsonSchema(MyBean.class);

        MAPPER.writeValue(new File("MyBeanSchema.json"), jsonSchema);

    }
}

MyBeans:

import java.util.Map;

public class MyBean {

    private Integer beanId;
    private String beanName;
    private Map<String, String> beanMap;
    private OtherBean otherBean;

    public MyBean() {
    }

    public Integer getBeanId() {
        return beanId;
    }

    public void setBeanId(Integer beanId) {
        this.beanId = beanId;
    }

    public String getBeanName() {
        return beanName;
    }

    public void setBeanName(String beanName) {
        this.beanName = beanName;
    }

    public Map<String, String> getBeanMap() {
        return beanMap;
    }

    public void setBeanMap(Map<String, String> beanMap) {
        this.beanMap = beanMap;
    }

    public OtherBean getOtherBean() {
        return otherBean;
    }

    public void setOtherBean(OtherBean otherBean) {
        this.otherBean = otherBean;
    }
}

其他豆类:

public class OtherBean {

}

【问题讨论】:

    标签: jackson fasterxml


    【解决方案1】:

    不直接回答您的问题,但 Schema Generation 正在转移到一个单独的模块:

    https://github.com/FasterXML/jackson-module-jsonSchema/

    它将具有更好的功能,并且可以比旧的内置一代更快地发展。 因此,如果可能,请尝试使用它。然后您可以针对生成问题提交错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-12
      • 2020-07-26
      • 2017-12-14
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2019-11-19
      • 2020-01-15
      相关资源
      最近更新 更多