XML serialization/deserialization description and control data:
Item hash:
- name: element or attribute name
- source: object attribute name, literal data string, nil for no contents
- +type: Ruby class name, Boolean short for "TrueClass or FalseClass", Literal for a literal element (no source attribute), default String if this is not the root element or the class being deserialized for the root element
- options: {options hash}, default {}
- *attributes: [array of item hashes describing attributes of this element], default []
- *children: [array of item hashes describing child elements of this element], default []
* = valid only in element item hashes, ignored in attribute item hashes
Options hash:
Options hash:
- *default: default value if source's value is nil, default no value
- trim: true/false, trim leading/trailing whitespace, default false
- elide: true/false, omit if value (after trimming if relevant) is nil or empty, default false
Control attributes on the object:
xml_attributes: an item hash describing the root element of the object
- Canonically the source would be nil, but a source attribute is legal if the root element will have actual text content.
- The type attribute of the root element defaults to the type of the object if not specified, and canonically it isn't specified since forcing a mismatching type will cause problems.
- The name attribute can be overridden by specifying an element name when serializing the object. When deserializing the root element's name is ignored and it's assumed the caller is deserializing the correct class.
- The key is the source attribute name.
- The value is nil or a string giving the element name to be used.
When serializing XML:
- If attributes is used then the attributes are serialized as child elements of the root and the default for include_types is true and use_source_names is true if the value is nil and false if the value names an element name. If xml_attributes is used the default for include_types and use_source_names is false. This allows the XML to be unchanged if an old-style attributes hash is being used.
- If xml_attributes is used then the attributes sub-hash is serialized first followed by the children sub-hash. Items with a nil source or Literal for type are ignored, they're relevant only to XML serialization.
- When deserializing, if type is absent then the type is determined by Ruby's default rules and the format of the value. Contained objects will end up deserialized to a hash and a class-specific attributes= method will be needed to recognize the attribute name, create an object of the correct class and initialize it with the hash before assigning it to the attribute.
- root_name: name of the root element if not the class name of the object
- include_types: include type and nil attributes in XML
- use_source_names: follow Ruby's naming conventions for element names
to_json options:
- include_root_in_json: include the class name as the root element of the JSON representation, default false
- include_all_roots_in_json: include the class name as the root element for all contained objects (implies include_root_in_json), default false