0

I am currently marshaling populated xjc classes to an xml file/string using jaxbDataFormat. However only populated fields are printing when I marshal. For example lets say version015v003 has 2 String fields, field1 and field2. I set field1 ="something" but dont set field2. I still want the generated xml to have both field1 and field2. As shown below. Any advice on how to achieve this?

<field1>something</field1>
<field2></field2>

JaxbDataFormat jaxbDataFormat =  new JaxbDataFormat("com.ups.brokerage.model.boss.version015v003");

from("direct:convertToEntryPacket")
        .routeId("BasXmlTranslation.mapToEntryPacket")
        .setExchangePattern(ExchangePattern.InOut)
        .bean("logging", "info(*, 'About to convert to entry packet')")
        .bean(entryPacketToBasMapper, "mapEntryPacketToBas(*)")
        .marshal(jaxbDataFormat)
        .bean("logging", "info(*, 'TRANSFORM: entry packet made... Message Body: ${body}')")
        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200))
        .convertBodyTo(String.class);
Connor Blair
  • 73
  • 2
  • 10

1 Answers1

0

Workaround: Convert null field to empty string (null -> "")

The workaround will make the field appear, but may result as <field2/>

For pure jaxb way, you may check other SO answer for default value or null field.

hk6279
  • 1,881
  • 2
  • 22
  • 32