admin管理员组文章数量:1313794
I'm using cxf xjc plugin version 4.0 to transform a schema to a java class, but this is generating a class that when a list is null, it returns an empty list, but I need the null, so I'm using JAXB binding to try to avoid this and get null when the list is empty or null,
the object containing MyList in my schema looks like:
<xs:complexType name="SomeObject">
<xs:sequence>
<xs:element maxOccurs="7" minOccurs="0" name="MyList" type="SomeType"/>
...
And SomeType is declared as:
<xs:simpleType name="SomeType">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="50"/>
....
JAXB is generating a List<String>
with this schema for MyList, but it's automatically returning empty list instead of null, I need to figure out how to avoid this. I cannot change the schema, also cannot change generated classes.
I'm trying to use an adapter for this, using bindings:
<jxb:bindings version="3.0"
xmlns:jxb=";
xmlns:xs=";>
<jxb:bindings schemaLocation="my-schema.xsd"
node="/xs:schema/xs:complexType[@name='SomeObject']/xs:sequence/xs:element[@name='MyList']">
<jxb:property>
<jxb:baseType>
<jxb:javaType name="java.util.List"
parseMethod="com.example.NullIfEmptyListAdapter.unmarshal"
printMethod="com.example.NullIfEmptyListAdapter.marshal"/>
</jxb:baseType>
</jxb:property>
</jxb:bindings>
</jxb:bindings>
but this makes myList to be a List<List>
.
And if I change javaType name to java.lang.String, then MyList is a <List<String>
, but the adapter doesn't work, because NullIfEmptyListAdapter is for <List<String>, List<String>>
and Adapter1 autogenerated is for <String, String>
.
So, using it as I have it right now, almost works, except it generates myList as a List<List>>
.
I need it null because I'm marshalling the class to an xml string, which is what I actually need, and empties create an empty tag which is invalid for schema.
The schema is way too big to use wrappers, that's why I would like to tackle MyList directly, but I don't have that much experience on XML to Java transformations and JABX bindings and stuff, I have tried in many many ways, this is the closest to work.
Like if I can just have MyList returning null instead of empty list, would be great.
Any suggestions much apprecciated.
本文标签:
版权声明:本文标题:java - CXF XJC generation force List<String> to return null instead of empty list with JABX bindings - Stack Overf 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741890884a2403294.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论