Repository navigation
3.6.0
The context can now supply an attribute's schema default when the attribute is absent, as a JAXB getter does. The default comes from the context and is never written into the data.
context.getDefaultValue('org_docx4j_wml.BooleanDefaultTrue', 'val'); // true
context.valueOrDefault(b, 'val'); // b.val if present, else trueWhat it reads. jsonix-schema-compiler already copies each xsd attribute default into the mappings it generates (defaultValue, short dv). Until now the runtime ignored it.
getDefaultValue(typeName, propertyName)looks on the class info namedtypeName(whatTYPE_NAMEcarries), then on its base types.- It returns
undefinedfor an attribute without a default, for an element property, and for a property the type does not declare. - It throws when the context has no class info of that name.
- It returns
valueOrDefault(object, propertyName, typeName?)returns the object's value when it exists (neitherundefinednornull, the test marshal uses to write it). Otherwise it returns the default fortypeName, or for the object'sTYPE_NAME.- It throws when there is neither, and for an unknown type, whether or not the value is present.
- Typings:
valueOrDefaultreturns the property's declared type, so an optional property stays optional.
What does not change. Unmarshal results and marshal output are what 3.5.0 produces.
<w:b/>still unmarshals without avalkey and marshals back as<w:b/>.<w:b w:val="true"/>stays explicit.- Code that tests a property for
undefinedsees the same data. - Element defaults are not applied: XSD gives them to a present, empty element, never to an absent one.
Why. docx4j's isVal() returns true for <w:b/>; in the TypeScript model each consumer had to know that itself. docx4j audited wml.xsd's boolean defaults against ECMA-376 and Word first (docx4j #697 and CR-059), so a mapping generated from it now gives the right answer: a real default, false, or no default where the value is inherited (e.g. w:lsdException's locked from w:latentStyles).
What a consumer must do. Nothing. Nothing changes until something calls the new methods.
Change request: docs/change-requests/jsonix-CR-009-schema-defaults-on-read.md