shawnuser3862921
shawnuser3862921

Reputation: 127

Jsonix enumerations

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?

Upvotes: 1

Views: 109

Answers (1)

lexicore
lexicore

Reputation: 43671

Disclaimer: I'm the author of Jsonix.

Yes, you can:

  • From the Jsonix context do 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.
  • You'll get an instance of your type info. In case of an enum this will be an instance of 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.

Upvotes: 0

Related Questions