Java-JAXB绑定排除字段
作者:互联网
我在Google周围逛了一圈,但是我敢肯定,这里有人可以比我更快地找到答案.我正在运行一个带有binding.xjb文件的XJC2Task(org.jvnet.jaxb2_commons.xjc.XJC2Task),以从某些XSD生成Java源代码.
我们正在考虑从数据中删除从第三方收到的一些个人信息.有没有一种方法可以将某些元素指定为@XMLTransient或从bindings.xjb文件中完全忽略它们?
因此,例如,如果我有以下xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="test.3.0" xmlns="test.3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="TestInfo" type = "TestInfo">
<xs:annotation>
<xs:documentation>TestInfo schema</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="TestInfo">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="id" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
在我的binding.xjb文件中
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jaxb:extensionBindingPrefixes="inheritance">
<jaxb:globalBindings>
<jaxb:serializable uid="1" />
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="schema/test.xsd">
<jaxb:schemaBindings>
<jaxb:package name="org.test" />
</jaxb:schemaBindings>
</jaxb:bindings>
有没有办法我可以从中删除ID?
我希望我不必重新学习XSLT即可完成此操作. ; D
解决方法:
您可以使用annox(jaxb2-basics-annotate)使用此绑定.
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:extensionBindingPrefixes="xjc annox"
version="2.1">
<jaxb:bindings schemaLocation="schema/test.xsd">
<jaxb:bindings
node="//xs:complexType[@name='TestInfo']//xs:sequence//xs:element[@name='id']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlTransient">
</annox:annotate>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
标签:xjc,types,jaxb,xsd,java 来源: https://codeday.me/bug/20191119/2036687.html