2014-02-07 20 views
0

我有一個使用FasterXML生成JSON模式文件的問題。 文件輸出只是示出了用於OtherBean 爲地圖和對象引用生成更快的XMLML模式

{ 「類型」

  • object類型爲Map<String, String>
  • null類型: 「對象」, 「屬性」:{ 「 beanId「:{ 」type「:」integer「 }, 」beanName「:{ 「類型」: 「串」 }, 「beanMap」:{ 「類型」: 「對象」 }, 「otherBean」:空 }}

我的架構生成類

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 { 

} 

回答

1

不能直接回答你的問題,但架構生成被移動到一個單獨的模塊:

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

這將有更好的功能,並且可以進化比老內置一代快。 所以如果可能的話,嘗試使用它。然後你可以針對這個問題提出錯誤,以解決代中的問題。