Populate xsi:type attribute on toXML(...) #518
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
I have an example here that reproduces the problem: https://github.com/abestel/scalaxb-failure/tree/bug/type_attribute
Basically, the WSDL defines types as:
So I have
ServiceRequest
<-MyRequest
<-MySubRequest
.The inheritance is expressed as
MyRequestable
=MyRequest
+MySubRequest
ServiceRequestable
=ServiceRequest
+MyRequestable
The generated formats are:
Here is a very simple example to see the issue:
The expected output would be:
The issue is that
xsi:type="MyRequest"
is not present in the generated XML with the current version of ScalaXB.Indeed, step by step, we have the following:
DefaultComtestgenerated_ServiceRequestableFormat#writes
, we match oncase x: com.test.generated.MyRequestable
and call anothertoXML
withtypeAttribute=true
DefaultComtestgenerated_MyRequestableFormat#writes
, we match oncase x: com.test.generated.MyRequest
and overridetypeAttribute
tofalse
Proposal
Actually use the
typeAttribute
that is propagated. Indeedwrites
takes it as an argument, so for traits we can just reuse the value for default cases.The generated code would be
In that case, the
typeAttribute=true
from step (1) would be reused in step (2) and the typeAttribute would actually be written.The behavior of an operation taking a
MyRequestable
would not change (thetypeAttribute
would not be written in that case).Note
Should solve #364 and I got inspired by #508