JAXB default for null elements when sorting

While sorting the JAXB object, I want to set some defult value to the resulting XML.

I don't want to use nillable=true

as it generates an empty tag with an unnecessary xsi:nil="true"

one and this is not to set the default. Instead, I want to generate XML with some placeholders like "?".

Use case: I'm going to build a WebService testing tool. There I need to present the entire xml request to the user (e.g. SOAPUI).

+3


source to share


1 answer


Use case: I'm going to create a WebService testing tool. There I need to present the entire xml request to the user (e.g. SOAPUI).

The placement owner idea won't really work. For example, ?

is the standard default for string, but not int, boolean, or more complex values ​​(that is, it represents nested address information for the client). Instead, you need a value that reflects the type.



Then I would have to write large and complex reflection based code. Let's just assume this is almost impossible in my case.

This reflection code probably won't be as bad as you imagine. A quick search will probably also reveal libraries that populate objects with "dummy" data. When connecting to JAXB, you can use Marshaller.Listener

to populate an object in a pre-marshal event.

+1


source







All Articles