When creating Jsonix (2.x) mapping files from xsd schema it captures enumerations and all the acceptable values, e.g.
{
type: 'enumInfo',
localName: 'TrackAdvanceNotificationStatusType',
baseTypeInfo: 'String',
values: ['BACK_ON_TRACK', 'FAIL']
}
Is there any way I can conveniently leverage these enumeration values from within my javascript code, or are they meant for Jsonix internal use only?
Disclaimer: I'm the author of Jsonix.
Yes, you can:
context.getTypeInfoByTypeNameKey('{urn:ns}TrackAdvanceNotificationStatusType')
to look up a type via XML Schema type name. In the next version you'll have a more convenient context.getTypeInfoByTypeName(...)
which accepts qualified names or strings.Jsonix.Model.EnumLeafInfo
.typeInfo.entries
is a key/value hashmap of string value/unmarshalled value.But here's a warning: I have not introduced a notion of public/private API yet. So there is certain minimal chance that this API will change in future versions. It is quite unlikely, but it's fair to warn.
It is better to use the type info prepared by Jsonix as it will have string values of enums as well as parsed values. For string-based enums it's irrelevant, but if you have other, non-string simple types you may be interested in "real" values.