Closed mastersang closed 6 months ago
Hi, glad finding this request. I am facing with feeding data from my custom model to generated java classes.
Currently adding nested complex elements like below:
withXXX(ClassC.builder().withA(null).withB(null).build())
results in an empty tag being marshalled: <someTag/>
withXXX(...)
calls addXXX(...)
and this adds list size 1 with empty element (all are null's)
using with call without arguments withXXX()
adds empty list with size=0 so now <someTag>
is omitted once marshalling.
So i need to do extra work each time in order to check manually if a model will contain some null fields and then decide which "withXXX" to apply.
Any idea on elegant solution to this issue?
Hi,
you could try to add „xsi:nillable“ to the elements in question, so they will be added in any case.
Am 2022-05-13 um 13:39 schrieb ryku @.***>:
Hi, glad finding this request. I am facing with feeding data from my custom model to generated java classes.
Currently adding nested complex elements like below: withXXX(ClassC.builder().withA(null).withB(null).build())
results in an empty tag being marshalled:
withXXX(...) calls addXXX(...) and this adds list size 1 with empty element (all are null's)
https://user-images.githubusercontent.com/8982833/168275554-ca486f59-9654-4ce2-aab5-8cf090d1d863.png using with call without arguments withXXX() adds empty list with size=0 so now
is omitted once marshalling. https://user-images.githubusercontent.com/8982833/168275566-8cc52874-bfb0-4170-b463-0aa15020496e.png So i need to do extra work each time in order to check manually if a model will contain some null fields and then decide which "withXXX" to apply.
Any idea on elegant solution to this issue?
— Reply to this email directly, view it on GitHub https://github.com/mklemm/jaxb2-rich-contract-plugin/issues/65#issuecomment-1125967334, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMTIUMGK7HKFE3SS4MYGVLVJY5NJANCNFSM4W63CREQ. You are receiving this because you are subscribed to this thread.
No planning on supporting this, even there might by some use for it in some situations. It's a very special requirement, though, and it won't work in all cases, since properties may be non-nullable and initialized with a default value, and you won't be able to tell inside the builder when properties are actually "not set" or set to their default value explicitly...
Suppose I have this class:
public class ClassC { private ClassA a; private ClassB b; }
Then I would like this lineClassC.builder().withA(null).withB(null).build()
to give me null instead of an object of type ClassC with both fields a and b null. Do you think this is a feasible extension?