如何使用 jaxb 生成 xml 标签作为完整的 class 名称?
How to generate xml tag as full class name using jaxb?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<batch-execution>
<insert out-identifier="employee" return-object="true" entry-point="DEFAULT">
<fact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="employee">
<name>Rajashekhar</name>
<age>21</age>
</fact>
</insert>
<fire-all-rules></fire-all-rules>
</batch-execution>
现在我得到了上面的输出,但我想像下面这样输出
<batch-execution>
<insert out-identifier="employee" return-object="true"
entry-point="DEFAULT">
<com.practise.Employee>
<name>Rajashekhar</name>
<age>21</age>
</com.practise.Employee>
</insert>
<fire-all-rules />
</batch-execution>
我的 Jaxb 类 是
Request.java
@XmlRootElement(name = "batch-execution")
@XmlAccessorType(XmlAccessType.FIELD)
public class Request implements Serializable {
@XmlElement(name = "insert")
private List<Insert> insert;
@XmlElement(name = "fire-all-rules",nillable=true)
private String fireAllRules = "";
.
..
setters and getter
Insert.java
@XmlAccessorType(XmlAccessType.FIELD)
public class Insert {
@XmlAttribute(name = "out-identifier", required = true)
private String outIdentifier;
@XmlAttribute(name = "return-object")
private boolean returnObject;
@XmlAttribute(name = "entry-point")
private String entryPoint;
private Object fact;
.
.
setters and gettes
com.practise.Employee.java
@XmlRootElement(name="kewill.com.kewill.practoise.Employee")
@XmlAccessorType(XmlAccessType.FIELD)
public class Employee implements java.io.Serializable
{
static final long serialVersionUID = 1L;
@org.kie.api.definition.type.Label("Name")
private java.lang.String name;
@org.kie.api.definition.type.Label("Id")
private java.lang.Integer id;
@org.kie.api.definition.type.Label("Age")
private int age;
@org.kie.api.definition.type.Label(value = "valid")
private java.lang.Boolean valid;
.
. setters and getters
我认为可以通过 xtream api 但我想使用 JAXB 请提供 jaxb 中的解决方案。
在Insert.java
为
添加了注释
private Object fact;
作为
@XmlAnyElement(lax = true)
private Object fact;
现在它给出了预期的输出。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<batch-execution>
<insert out-identifier="employee" return-object="true" entry-point="DEFAULT">
<fact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="employee">
<name>Rajashekhar</name>
<age>21</age>
</fact>
</insert>
<fire-all-rules></fire-all-rules>
</batch-execution>
现在我得到了上面的输出,但我想像下面这样输出
<batch-execution>
<insert out-identifier="employee" return-object="true"
entry-point="DEFAULT">
<com.practise.Employee>
<name>Rajashekhar</name>
<age>21</age>
</com.practise.Employee>
</insert>
<fire-all-rules />
</batch-execution>
我的 Jaxb 类 是
Request.java
@XmlRootElement(name = "batch-execution")
@XmlAccessorType(XmlAccessType.FIELD)
public class Request implements Serializable {
@XmlElement(name = "insert")
private List<Insert> insert;
@XmlElement(name = "fire-all-rules",nillable=true)
private String fireAllRules = "";
.
..
setters and getter
Insert.java
@XmlAccessorType(XmlAccessType.FIELD)
public class Insert {
@XmlAttribute(name = "out-identifier", required = true)
private String outIdentifier;
@XmlAttribute(name = "return-object")
private boolean returnObject;
@XmlAttribute(name = "entry-point")
private String entryPoint;
private Object fact;
.
.
setters and gettes
com.practise.Employee.java
@XmlRootElement(name="kewill.com.kewill.practoise.Employee")
@XmlAccessorType(XmlAccessType.FIELD)
public class Employee implements java.io.Serializable
{
static final long serialVersionUID = 1L;
@org.kie.api.definition.type.Label("Name")
private java.lang.String name;
@org.kie.api.definition.type.Label("Id")
private java.lang.Integer id;
@org.kie.api.definition.type.Label("Age")
private int age;
@org.kie.api.definition.type.Label(value = "valid")
private java.lang.Boolean valid;
.
. setters and getters
我认为可以通过 xtream api 但我想使用 JAXB 请提供 jaxb 中的解决方案。
在Insert.java
为
添加了注释private Object fact;
作为
@XmlAnyElement(lax = true)
private Object fact;
现在它给出了预期的输出。