FasterXML schema generation for Maps and Object references

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 {

}

Answers


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.


Need Your Help

method readUnsignedByte in PHP

php byte unsigned

how get UnsignedBytes in php? In java very easy: readUnsignedByte (Java)

Is there a faster way to run test-app repeatedly in Eclipse STS?

eclipse grails junit

Running test-app under Eclipse STS is slow for me because it has to start up the Grails app stack each time. On the command line I can run Grails interactively then run "test-app -functional" and ...