Skip to content

3.6.0

Choose a tag to compare

@plutext plutext released this 23 Oct 20:08
· 22 commits to master since this release

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 true

What 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 named typeName (what TYPE_NAME carries), then on its base types.
    • It returns undefined for 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.
  • valueOrDefault(object, propertyName, typeName?) returns the object's value when it exists (neither undefined nor null, the test marshal uses to write it). Otherwise it returns the default for typeName, or for the object's TYPE_NAME.
    • It throws when there is neither, and for an unknown type, whether or not the value is present.
  • Typings: valueOrDefault returns 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 a val key and marshals back as <w:b/>.
  • <w:b w:val="true"/> stays explicit.
  • Code that tests a property for undefined sees 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