xml-class-transformer / XmlAttributeOptions
• Optional marshaller: Marshaller<unknown>
A custom marshaller.
Not compatible with the type options.
Example
class CapitalizedBooleanMarshaller implements Marshaller<boolean> {
marshal(obj: boolean): string {
return obj ? 'True' : 'False';
}
unmarshal(chardata: string | undefined): boolean {
return chardata == 'True' ? true : false;
}
}
@XmlAttribute({ marshaller: new CapitalizedBooleanMarshaller() })
isSomethingEnabled: boolean;Example
const momentMarshaller: Marshaller<moment.Moment> = {
marshal = (val: moment.Moment): string => val.toISOString(),
unmarshal = (chardata: string): moment.Moment => moment(chardata) ,
}
@XmlAttribute({ marshaller: momentMarshaller })
creationDateOfSomething: moment.Moment;• Optional name: string
XML attribute name. If not specified, the property name will be used.
• Optional type: () => XmlPrimitiveType
▸ (): XmlPrimitiveType
XML Attributes can only be of primitive types. Specify the primitive type for parsing and serializing the attribute.
Not compatible with the marshaller options.
Example
{ type: () => String }
{ type: () => Number }
{ type: () => Boolean }
{ type: () => BigInt }
{ type: () => Date }
{ type: () => CustomClass }