简体   繁体   中英

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>

Now I am getting this output as above but I want out put like below

    <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>

My Jaxb classes are

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

I think it is possible through xtream api but I want to use JAXB please provide me the solution in jaxb.

In Insert.java

added Annotation for

private Object fact;

as

@XmlAnyElement(lax = true)
private Object fact;

Now it is giving expected output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM