According to the wiki page of Jsonix regarding its support for xsi:type
:
When marshalling, Jsonix checks, if the value has the same type as declared in the property or element declaration
I'm wondering if there is a way to explicitly get Jsonix to generate that attribute? I was able to do that in another project by specifying the TYPE_NAME
property, i.e.
element: {
TYPE_NAME: 'mapping.Element',
xAttr1: '1',
xAttr2: '2',
content: 'some content',
},
Now i'm doing some XML exports again but the same approach doesn't work any more, i.e. i get the correct xml but the xsi:type
is missing. Here is a working fiddle using a stripped down version of my mappings, that shows how an item is unmarshalled with a type and then is being marshalled without one.
In your example, your unmarshalled Title
has the type Mappings.SomeType
, which matches your mappings. So Jsonix does not need to output xsi:type
as there's a match.
If I understand you correctly, you want Jsonix to always output xsi:type
. Not sure why you need this, but this is not supported OOTB.
You will probably need to patch Jsonix to get this. Here is where Jsonix decides whether to add xsi:type
or not:
Since I don't quite see the need of forcing xsi:type
output in general, I don't think this functionality should be included in Jsonix. So you'll probably end up with your own fork.