Repository navigation
3.7.0
One attribute value its type refuses no longer has to fail the whole unmarshal. Two per-call callbacks hand such a value to the caller instead:
context.createUnmarshaller({ onInvalidValue: function (text, propertyInfo, classInfo, node, error) { /* ... */ } })
context.createMarshaller({ onUnprintableValue: function (value, propertyInfo, classInfo, error) { /* ... */ } })Unmarshal. onInvalidValue is called only after an attribute's value has failed its type's parse: a boolean outside true, 1, on, false, 0 and off, a value outside an enumeration, a number or date that does not parse.
- A returned value is stored as the property's value, unchecked.
undefinedornullleaves the property unset.- A throw aborts the unmarshal and is located with element, attribute and line, as today. Rethrowing
errorreproduces today's message exactly.
Marshal. onUnprintableValue is called when an attribute value fails its type's print, for example a string kept outside its enumeration. A returned string is written, and undefined or null omits the attribute.
Scope. The callbacks receive the class info, and classInfo.module.name names its module. A caller can therefore apply a rule to one vocabulary and rethrow everything else. In a WordprocessingML part, w: values can be read by Word's rules while the DrawingML inside stays strict. The runtime itself holds no Word rules.
Typings. Both callbacks are declared, and so are AttributePropertyInfo (typeInfo, attributeName, defaultValue), ClassInfo.module and TypeInfo.CLASS_NAME. TypeScript callers can dispatch on propertyInfo.typeInfo.name === 'Boolean' or on propertyInfo.typeInfo.CLASS_NAME === 'Jsonix.Model.EnumLeafInfo'.
Why. Word 365 opens documents holding values such as <w:b w:val="FALSE"/>, which it reads as on, and <w:u w:val="Single"/>, which it reads as unset. Until now one such value made @docx4j/generated-objects-ts and @docx4j/core-ts refuse the whole part, so nothing in it could be read.
What a consumer must do. Nothing. With neither callback set, behaviour, errors and output are unchanged.
Change request: docs/change-requests/jsonix-CR-010-invalid-attribute-values-to-the-caller.md