jsonix
jsonix copied to clipboard
Exclude TYPE_NAME property from objects
Is it possible to exclude the TYPE_NAME property from JS objects after unmarshalling?
Not at the moment. TYPE_NAME is needed for marshalling in some cases.
Thanks. That's what I thought.
What kind of cases need it in addition to the PO for for marshalling?
I'm mostly using Jsonix for importing to a similar JSON format as the XML, but would like there possibility of exporting to XML again. I'm wondering if I could remove it programmatically so as to keep the JSON clean and compact, but still be able to export.
You'll need TYPE_NAME for elements property with complex type. This property allows you to map different XML elements onto one property in JavaScript. The specific element name depends on the type of the value, like <s>1</s><i>2</i> may be represented as ['1', 2].
To marshal this correctly, Jsonix will need to distinguish types of values. This is trivial for primitive types. To distinguish types of objects, Jsonix uses the TYPE_NAME property.
If you don't have elements property in you mapping, you can safely drop TYPE_NAME.