- Added
json.enum_format
settings. To define if parsing is done bybyIndex
orbyName
. Defaults tobyName
. - Added support to default values inside custom collections. Ex:
Color(x as int? ?? 0)
. - Refactor and minor improvements.
- Renamed
isA<T>
tocast<T>
for better readability. - Added
"// ignore_for_file: type=lint"
tocustom.headerLines
as default import line. - Added settings support to custom types serialization. Ex:
Color((x as num).toInt())
. - Added support to safe nested collections serialization. Ex:
List<Map<String, dynamic>>
. - Refactor and minor improvements.
Obs: Further nesting won't be supported. For those, use e.g: List<List>
instead of List<List<List<int>>>
.
- Added
strict_numbers
. "If true,int
anddouble
will usecast<int>(...)
instead ofcast<num>(...).toInt()
sintax." - Fix
Generate from Json
missingclass
keyword.
- Removed internal default directives.
- Add custom type directives to
fromMap
andtoMap
directly in settings.
Example:
"dart-data-class-generator.custom.types": [
{
"type": "DateTime",
"fromMap": "DateTime.parse(String)",
"toMap": "toIso8601String()"
},
//...others,
]
It follows the same rules as of comment-directives.
final DateTime createdAt; // DatTime.parse(String), toIso8601String()`
The generator will prioritize the comment-directive first and then the custom type directives defined in settings.
- Make sealed and final class compatible. Sealed will behave as abstract and final will behave as concrete.
- Use
Map.from
instead ofas Map<String, dynamic>
for correctly parsingMap<dynamic, dynamic>
types.
New features:
- New setting: custom.headerLines. Adds header lines that shows on top of the generated file.
- New settings: constructor.immutable. Adds @immutable annotation on the generated class.
- New behavior: Add
const
keyword on constructor if the class has no constructor and all properties are final or if contructor.immutable is set to true.
Refactor to better reflect EffectiveDart style:
- Changed fromMap.cast:
T cast<T>(String k) => map[k] is T ? map[k] as T : throw ...
. - Added
as Map<String, dynamic>
to fromJson.decode.
- Added custom.argumentError config in settings. Customize isA() error. Defaults to: "throw ArgumentError.value(map[k], k, '$T ← ${map[k].runtimeType}');"
- Fix minor bugs.
- Added option to ignore serialization with
//ignore
- Fixed serialization of custom list types.
- Improved the regular expression used for parsing directives to correctly handle nested parentheses and brackets.
- Fixed comment-directive conflicts with
//enum
. - Fixed nested json serialization types comming with unnecessary "?" in mapping.
Introducing Custom Serialization: You can now implement your own custom from/to methods for serialization using comment-directives. Refer to the README for details.
Added ArgumentError Safety:
-
isA<T>()
was added to TypeSafe arguments. -
Default Values won't be called on required arguments anymore, unless set on settings.
-
Solved dynamic casts and getters called on dynamic.
-
Now you can mark enums with a comment-directive. Ex:
final MyEnum type; // enum
. -
Fixed unnecessary null check marks on custom classes.
-
Added support to Timestamp and improved DateTime, Color and IconData.
-
Refactor and minor improvements.
- Updated the badges in README.md.
Added support for snake_case json keys Generate toString() when converting with Equatable Other improvements
Added support for enums Use factory constructors instead of static methods for json serialization
Added support for value equality on Lists
, Maps
and Sets
.
Class fields can now also be declared after the constructor. Minor improvements.
Fixed some bugs.
Added support for equatable by setting dart-data-class-generator.useEquatable to true.
Changed setting dart-data-class-generator.constructor
to dart-data-class-generator.constructor.enabled
Changed setting dart-data-class-generator.copyWith
to dart-data-class-generator.copyWith.enabled
Changed setting dart-data-class-generator.toMap
to dart-data-class-generator.toMap.enabled
Changed setting dart-data-class-generator.fromMap
to dart-data-class-generator.fromMap.enabled
Changed setting dart-data-class-generator.toJson
to dart-data-class-generator.toJson.enabled
Changed setting dart-data-class-generator.fromJson
to dart-data-class-generator.fromJson.enabled
Changed setting dart-data-class-generator.toString
to dart-data-class-generator.toString.enabled
Changed setting dart-data-class-generator.equality
to dart-data-class-generator.equality.enabled
Changed setting dart-data-class-generator.hashCode
to dart-data-class-generator.hashCode.enabled
Added quick fixes.
Added support for @required annotation. Changed the default hashCode implementation to bitwise operator.
Initial release (Beta).