java - When generating beans from dtd with xjc default values are in getter methods -
i use xjc create objects dtd.
xjc -dtd mydtd.dtd -d src
but confused default values...
in dtd file have element below:
<!element imageorder (target, format, source, output, rules?, volumename?, pvdinfo?, controls?, customize?)> <!attlist imageorder orderid cdata #required clientid cdata #required priority (low | normal | high) "normal" streamerexternal (true | false) "false" streamerlogonid cdata #implied>
and xjc creates object below:
@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "", proporder = { "target", "format", "source", "output", "rules", "volumename", "pvdinfo", "controls", "customize" }) @xmlrootelement(name = "imageorder") public class imageorder { @xmlattribute(name = "orderid", required = true) @xmljavatypeadapter(normalizedstringadapter.class) protected string orderid; @xmlattribute(name = "clientid", required = true) @xmljavatypeadapter(normalizedstringadapter.class) protected string clientid; @xmlattribute(name = "priority") @xmljavatypeadapter(collapsedstringadapter.class) protected string priority; @xmlattribute(name = "streamerexternal") @xmljavatypeadapter(collapsedstringadapter.class) protected string streamerexternal; . . . . . public string getpriority() { if (priority == null) { return "normal"; } else { return priority; } } . . . public string getstreamerexternal() { if (streamerexternal == null) { return "false"; } else { return streamerexternal; } }
and want marshal new imageorder instance. when marshalling default values not set. want marshal default values. how can this.
imageorder imageorder = new imageorder(); imageorder.setorderid("orderid"); imageorder.setclientid("clientid"); jaxbcontext context = jaxbcontext.newinstance(imageorder.class); stringwriter stringwriter = new stringwriter(); marshaller marshaller = context.createmarshaller(); marshaller.setproperty(marshaller.jaxb_encoding, "utf-16"); marshaller.setproperty(marshaller.jaxb_formatted_output, true); marshaller.setproperty(marshaller.jaxb_fragment, false); marshaller.marshal(obj, stringwriter);
expected xml:
<imageorder clientid="clientid" orderid="orderid" priority="normal" streamerexternal="false"> </imageorder>
but this:
<imageorder clientid="clientid" orderid="orderid"> </imageorder>
Comments
Post a Comment