如何使用jaxb生成xml标记作为完整的类名?

时间:2015-06-24 07:21:38

标签: java xml jaxb jaxb2

<?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中提供解决方案。

1 个答案:

答案 0 :(得分:0)

在Insert.java中

添加了注释
private Object fact;

作为

@XmlAnyElement(lax = true)
private Object fact;

现在它正在给出预期的输出。