Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for custom output formatting #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tnc1997
Copy link

@tnc1997 tnc1997 commented May 29, 2023

This change adds support for custom output formatting and is inspired by #29 and google/json_serializable.dart#179. I am currently in the process of rewriting the tests in xml_serializable to use this package instead of the generator directly and it would be very useful (and more performant) to be able to skip the formatting of the generated source code.

Before
@ShouldGenerate(r'''
void _$StringHappyPathBuildXmlChildren(
    StringHappyPath instance, XmlBuilder builder,
    {Map<String, String> namespaces = const {}}) {
  final value = instance.value;
  final valueSerialized = value;
  builder.attribute('value', valueSerialized);
}

StringHappyPath _$StringHappyPathFromXmlElement(XmlElement element) {
  final value = element.getAttribute('value')!;
  return StringHappyPath(value: value);
}

List<XmlAttribute> _$StringHappyPathToXmlAttributes(StringHappyPath instance,
    {Map<String, String?> namespaces = const {}}) {
  final attributes = <XmlAttribute>[];
  final value = instance.value;
  final valueSerialized = value;
  final valueConstructed = XmlAttribute(XmlName('value'), valueSerialized);
  attributes.add(valueConstructed);
  return attributes;
}

List<XmlNode> _$StringHappyPathToXmlChildren(StringHappyPath instance,
    {Map<String, String?> namespaces = const {}}) {
  final children = <XmlNode>[];
  return children;
}
''')
@XmlSerializable()
class StringHappyPath {
  @XmlAttribute()
  String value;

  StringHappyPath({required this.value});
}
After
@ShouldGenerate(r'''
void _$StringHappyPathBuildXmlChildren(StringHappyPath instance, XmlBuilder builder, {Map<String, String> namespaces = const {}}) {
final value = instance.value;
final valueSerialized = value;
builder.attribute('value', valueSerialized);
}

StringHappyPath _$StringHappyPathFromXmlElement(XmlElement element) {
final value = element.getAttribute('value')!;
return StringHappyPath(value: value);
}

List<XmlAttribute> _$StringHappyPathToXmlAttributes(StringHappyPath instance, {Map<String, String?> namespaces = const {}}) {
final attributes = <XmlAttribute>[];
final value = instance.value;
final valueSerialized = value;
final valueConstructed = XmlAttribute(XmlName('value'), valueSerialized);
attributes.add(valueConstructed);
return attributes;
}

List<XmlNode> _$StringHappyPathToXmlChildren(StringHappyPath instance, {Map<String, String?> namespaces = const {}}) {
final children = <XmlNode>[];
return children;
}''')
@XmlSerializable()
class StringHappyPath {
  @XmlAttribute()
  String value;

  StringHappyPath({required this.value});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant