Skip to content

Latest commit

 

History

History
98 lines (64 loc) · 2.13 KB

File metadata and controls

98 lines (64 loc) · 2.13 KB

xml-class-transformer / XmlAttributeOptions

Interface: XmlAttributeOptions

Table of contents

Properties

Properties

marshaller

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;

Defined in

src/types.ts:183


name

Optional name: string

XML attribute name. If not specified, the property name will be used.

Defined in

src/types.ts:140


type

Optional type: () => XmlPrimitiveType

Type declaration

▸ (): 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 }
Returns

XmlPrimitiveType

Defined in

src/types.ts:156