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

DocumentationL Custom Mapper #8

Closed
xErik opened this issue Mar 22, 2022 · 2 comments
Closed

DocumentationL Custom Mapper #8

xErik opened this issue Mar 22, 2022 · 2 comments

Comments

@xErik
Copy link

xErik commented Mar 22, 2022

dart_mappable: ^0.9.1

Hi there, writing my own CustomMapper I have a suggestion for the documentation.

Maybe something along the lines below, demonstrating the handling of a slightly more complex situation involving custom objects and not just a String.

The current example shows decode: return (value as String) which may be outdated?

--------------------------------------------------

@CustomMapper()
class ItemRefMapper extends SimpleMapper<ItemRef> {
  ItemRefMapper();
  final String key = 'aSuperJsonKey';

  @override
  ItemRef decode(dynamic value) {
    return ItemRef(value[key]);
  }

  @override
  dynamic encode(ItemRef self) {
    return {key: self.val};
  }
}

class ItemRef {
  String val;
  ItemRef(this.val);

  @override
  String toString() {
    return val;
  }
}

@MappableClass(discriminatorKey: 'type')
abstract class Data {
  ItemRef itemRef;
  Data(this.itemRef);
}

@MappableClass()
class DataImpl extends Data {
  DataImpl(ItemRef itemRef) : super(itemRef);
}
@schultek
Copy link
Owner

Thanks for the feedback.

Maybe to both keep it simple and have a meaningful example, I could show a custom mapper for some core dart class, like Uri or BigInt?

@xErik
Copy link
Author

xErik commented Mar 26, 2022

Sure! Showing that a HashMap may be returned in decode would be helpful. I was not so sure what to expect and how to make it work in the beginning.

Thanks!

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

No branches or pull requests

2 participants