i want output xml this:
<master> <list type="array" nil="true"> <master>
i have tried @xmlattribute
, @xmlelement(nil=true)
, how should jaxb.
<slave-status><connect-retry type="integer" nil="true"/> <created_at type="datetime" nil="true"/> <slave-status>
master.java
import javax.xml.bind.jaxbelement; import javax.xml.bind.annotation.xmlaccesstype; import javax.xml.bind.annotation.xmlaccessortype; import javax.xml.bind.annotation.xmlelement; import javax.xml.bind.annotation.xmlrootelement; import javax.xml.bind.annotation.xmltype; @xmlrootelement @xmlaccessortype(xmlaccesstype.field) @xmltype(name = "master", proporder = { "list" }) public class master { @xmlelement(name = "list") protected list list; public list getlist() { return list; } public void setlist(list value) { this.list = value; } }
list.java
import javax.xml.bind.annotation.xmlaccesstype; import javax.xml.bind.annotation.xmlaccessortype; import javax.xml.bind.annotation.xmlattribute; import javax.xml.bind.annotation.xmltype; @xmlaccessortype(xmlaccesstype.field) @xmltype(name = "list") public class list { @xmlattribute(name = "type") protected string type; @xmlattribute(name = "nil") protected boolean nil; public boolean isnil() { return nil; } public void setnil(boolean nil) { this.nil = nil; } public string gettype() { return type; } public void settype(string value) { this.type = value; } }
package-info.java
@javax.xml.bind.annotation.xmlschema(namespace = "", elementformdefault = javax.xml.bind.annotation.xmlnsform.qualified) package com.ca.exporter.util;
main.java
import javax.xml.bind.jaxbcontext; import javax.xml.bind.jaxbexception; import javax.xml.bind.marshaller; public class main { public static void main(string[] args) throws jaxbexception { jaxbcontext jc = jaxbcontext.newinstance(master.class); master m = new master(); list l = new list(); l.settype("array"); l.setnil(true); m.setlist(l); marshaller mar = jc.createmarshaller(); mar.marshal(m, system.out); } }
output - xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <master> <list type="array" nil="true"/> </master>