如何让 JAXB 编码字符串或原始数据类型并在生成的 XML 中设置 type="string"或 type="int"。我尝试为每个字段指定特定类型
@XmlSchemaType(name = "string",namespace = "http://www.w3.org/2001/XMLSchema",type = String.class)
但这并没有什么区别,结果 XML 没有类型。
感谢您的阅读
更新 这基本上就是我在 JaxB 类中的内容:
@XmlElement(required = true)
protected Keys keys;
protected String workflowID;
protected String fromFigure;
protected String fromPort;
这是生成的 XML
<keys type="draw2d.ArrayList">
<data type="Array">
<element type="draw2d.FlowConnectionModel">
<workflowID>d8f71b92-dc69-4115-9095-d748265d4e68</workflowID>
<fromFigure>706531d9-cd03-4347-9ba2-d9b525035e0d</fromFigure>
<fromPort>out_right_initialState</fromPort>
请注意,有一个针对键、数据和元素类型的类型集,但没有针对工作流 ID、fromFigure 和 fromPort 的原始数据类型的类型集。我想要的是这样的:
<keys type="draw2d.ArrayList">
<data type="Array">
<element type="draw2d.FlowConnectionModel">
<workflowID type="string">d8f71b92-dc69-4115-9095-d748265d4e68</workflowID>
<fromFigure type="string">706531d9-cd03-4347-9ba2-d9b525035e0d</fromFigure>
<fromPort type="string">out_right_initialState</fromPort>
最佳答案
您不会在生成的 XML 中看到任何差异。如果您从类中生成 XSD,您预计会看到 XSD 的差异。
关于java - jaxb设置字符串类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9398486/