Question

I have an issue generating a JSON Schema file with FasterXML. The file output just shows

  • object type for a Map<String, String>
  • null type for OtherBean

{ "type": "object", "properties": { "beanId": { "type": "integer" }, "beanName": { "type": "string" }, "beanMap": { "type": "object" }, "otherBean": null } }

My Schema generation class

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

OtherBean:

public class OtherBean {

}
Was it helpful?

Solution

Not directly answering your question, but Schema Generation is moving to a separate module:

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

which will have better functionality, and can evolve faster than old in-built generation. So if possible, try using that. And then you can file bugs against this, for problems with generation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top