0

Update: please notice this is not a duplicate because most of the solutions includes modifying the model which I'm unable to do.

I got a requirement to change the XML in a SOAP request to use short tags whenever possible.

Even though the effect is the same, I need to replace:

<MyObject></MyObject> long tag

with

<MyObject/> short tag

While doing so I noticed that both the default javax JAXB and Moxy will:

  • create a short tag when Marshalling MyObjects that I instantiate with new and don't populate the members
  • create a long tag when the object being Marshalled is a String.

Is this a known bug on JAXB?

I understand that with Moxy I could use a DescriptorCustomizer (like the one mentioned here) to control the behavior of null values but I'm using a proprietary library which I can't change.

Is there a way to change this behavior while creating the marshaller?

douglaslps
  • 8,068
  • 2
  • 35
  • 54
  • 1
    It's not a bug as long tag and short tag are two different syntaxes to represent perfectly identical data. If you have the additional requirement to ensure it looks short, you could add a pass of your XML through a Transformer, as when not told to use identation they try to keep it short, or you could make it sure with a pass through a library that lets you control it, such as JDOM's XMLOutputter. – kumesana Sep 26 '17 at 18:40
  • you are right. Using a transformer is indeed the way to go. Thanks. If the question gets reopened I can post the code for the transformer. – douglaslps Sep 26 '17 at 19:10

0 Answers0