add 'dartCompatible' option to MappableClass #155
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an attempt to address #82. Unfortunately most other Dart libraries that involve serialization automatically expect
toJson()
/fromJson()
methods to return/accept aMap
, rather than aString
. I preferdart_mappable
's naming convention, however, as was mentioned in that thread, the Dart convention is widespread.This adds a
dartCompatible
option toMappableClass
and to theglobalOptions
that, whentrue
, will rename the methods. Note that if someone uses therenameMethods
options, those will take priority. The biggest advantage of this PR is the ability to customize Dart compatibility on each individual class.dartCompatible
isfalse
by default so it will not break any compatibility unless you specifically turn it on.The renaming policy is:
There is also a test group demonstrating a class annotated with
dartCompatible: true
compared to the default. (I did not write tests for the global option or for Records)Of course, an alternate philosophy is to decide that going forward, this package should aim for widespread Dart compatibility. One could rename all the generated methods to comply, and require a
legacy: true
option in order to preserve the current naming convention. This would break compatibility, but easily fixed viaA PR that followed this concept would be basically the same PR but with every boolean flipped.