[英]how to generate java class from xsd by using xmlbeans in gradle
[英]How to generate Long class type variable from xsd in java
我正在使用xsd生成我的模型,以下是我的xsd文件之一,使用它我正在生成Generator
模型,这里我的问题是我想要一个变量的类型是Long
类类型但我得到long
premitive数据类型。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc" jaxb:version="1.0">
<xsd:complexType name="Generator">
<xsd:sequence>
<xsd:element name="id" type="xsd:string" minOccurs="1" />
<xsd:element name="name" type="xsd:string" minOccurs="1" />
<xsd:element name="age" type="xsd:int" minOccurs="1" />
<xsd:element name="timestamp" type="xsd:long" minOccurs="1" />
</xsd:sequence>
</xsd:complexType>
生成的类如下: -
public class Generator
implements Cloneable, CopyTo, Equals, ToString
{
@XmlElement(required = true)
protected String id;
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected int age;
@XmlElement(required = true)
protected long timestamp;
// settter and getter methods
}
生成的timestamp
值的类型为long
但我希望它的类型为Long
几天前我遇到了类似的问题。 在玩了xsd之后,我发现了以下两点:
这是有道理的,因为必填字段需要具有默认值。 回到你的情况,如果你想timestamp
是Long,那么删除minOccurs
。 希望能帮助到你。
我在XSD中也面临同样的问题,而我需要对象而不是原始对象。
对于您的情况,请尝试下面给出的选项4。 它应该工作,因为它也为我工作。
type =“xs:long”minOccurs =“0”maxOccurs =“1”>(生成) - 长值(对象)
type =“xs:long”minOccurs =“0”maxOccurs =“1”nillable =“true”>(生成) - JAXBElement值(对象)
type =“xs:long”minOccurs =“1”maxOccurs =“1”>(生成) - 长值(原始)
我知道这是非常晚的回复,但它可能会帮助那些面临这些问题的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.