[英]How can I construct XSD to have primitive wrapper instead of primitive type in generated JAXB class?
I have following attribute in my XSD: 我的XSD中具有以下属性:
<xs:attribute name="fromFraction" type="xs:float" use="optional" default="0.0"/>
I generate class from this XSD and attribute is created as float
, and then I can't marshall XML without this attribute from this class (as far as I understand, in that case it will always have some value which will be marshalled). 我从此XSD生成类,并且将属性创建为
float
,然后如果没有此类中的该属性,就无法编组XML(据我所知,在这种情况下,它将始终具有将被编组的某些值)。
How can I change the XSD to create a Float
type during binding , so I can have null in this field (so it could be omitted during marshalling)? 如何在绑定期间更改XSD以创建
Float
类型 ,以便在此字段中可以使用null(以便在编组期间将其省略)?
Or maybe there is a better way to remove this attribute from resulting XML when it isn't present? 或者,也许有更好的方法从不存在的XML中删除此属性?
According to this: http://reast.net/2009/08/jaxb-generating-primitive-type-getters/ and its reference: http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/jaxb/vendorCustomizations.html#serializable 据此: http : //reast.net/2009/08/jaxb-generating-primitive-type-getters/及其参考: http : //docs.oracle.com/cd/E17802_01/webservices/webservices/docs/ 1.5 / JAXB / vendorCustomizations.html#序列化
you should add this to your XSD: 您应该将此添加到您的XSD:
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:serializable uid="12343"/>
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
I had following line in binding.xjb file which I used to generated classes: 我在binding.xjb文件中有以下代码,我曾经用来生成类:
<jxb:globalBindings optionalProperty="primitive"/>
When I removed it, generated classes contain proper primitive-wrappers, just as I wanted. 当我删除它时,生成的类包含适当的原始包装器,正如我想要的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.