0

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

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

{“类型”:“对象”,“属性”:{“beanId”:{“类型”:“整数”},“beanName”:{“类型”:“字符串”},“beanMap”:{“类型” :“对象”},“其他豆”:空}}

我的模式生成类

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);

    }
}

我的豆子:

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 {

}
4

1 回答 1

1

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

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

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

于 2014-02-07T18:48:46.427 回答