Skip to content

feat: add support for custom output formatting#44

Open
tnc1997 wants to merge 12 commits intokevmoo:masterfrom
tnc1997:feat/29
Open

feat: add support for custom output formatting#44
tnc1997 wants to merge 12 commits intokevmoo:masterfrom
tnc1997:feat/29

Conversation

@tnc1997
Copy link
Copy Markdown

@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});
}

@tnc1997
Copy link
Copy Markdown
Author

tnc1997 commented Sep 8, 2025

@kevmoo thank you very much for your work on this package!

I was wondering if you might be able to review these changes when you have a bit of time spare?

@kevmoo
Copy link
Copy Markdown
Owner

kevmoo commented Mar 7, 2026

I will! Thanks for your patience!

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.

2 participants