tnc1997 / dart-xml-serializable

Generates utilities to aid in serializing to/from XML.

Home Page:https://pub.dev/packages/xml_serializable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reduce boilerplate code

atn832 opened this issue · comments

I tried writing the simplest class:

import 'package:xml_annotation/xml_annotation.dart' as annotation;

part 'character.g.dart';

@annotation.XmlRootElement(name: 'character')
@annotation.XmlSerializable()
class Character {}

And ran the generator. It generated the character.g.dart class but it had a compile error:

The method 'buildXmlChildren' isn't defined for the type 'Character'. Try correcting the name to the name of an existing method, or defining a method named 'buildXmlChildren'.

It would be nice to handle the simplest use cases to allow us to write even less boilerplate code. Judging from your readme example, i would still need to implement a few more methods for it to compile.

Hi @atn832, thank you very much for your issue. It looks like your class doesn't have any fields and does not have the required methods to support XML serialization using this package. You could reduce the number of methods that you have to implement in your class by using the create mixin functionality provided by the XmlSerializable annotation.