dto_logger 2.1.1
dto_logger: ^2.1.1 copied to clipboard
Debug-only logging and safe type coercion for JSON DTOs in Flutter/Dart. Generate classes from JSON, see nulls, missing keys, type mismatches and unused fields per model.
2.1.1 #
- README: a numbered list of what the package does, linking to each section.
2.1.0 #
injecttakes a single file as well as a folder, with or without--dir:dart run dto_logger:inject lib/models/user.dart.- README: organized by use case, with a screenshot of the real output under each feature. The full demo moved to a collapsed section.
- Package page: more screenshots.
2.0.1 #
- README: a demo of every feature at the top.
- Package page: a screenshot.
2.0.0 #
Breaking #
- The
@DtoLogbuilder moved to a new package,dto_logger_generator. If you use@DtoLog, add it next tobuild_runner:
The annotations stay indev_dependencies: build_runner: ^2.10.0 dto_logger_generator: ^1.0.0dto_loggerand the generated code is the same, except that a field read withsafeCastkeeps nullable type arguments (Map<String, int?>was read asMap<String, int>).package:dto_logger/builder.dartis gone. If yourbuild.yamlconfigures the builder, renamedto_logger:dto_loggertodto_logger_generator:dto_logger.
Changed #
dto_loggerhas no dependencies now. Before, itssource_gen ^1.5.0made it impossible to add next to currentjson_serializableorfreezed, which needsource_gen3 or newer.pubspec.yamllinks to the repository and issue tracker.
Fixed #
DtoMockprices and coordinates had floating point noise (29.990000000000002). They are exact now (29.99).DtoMockgaveavatar_urlandimage_urla plain page URL. They get image URLs now.- A timestamp sent as a string (
"1704067200") was reported aswas int (seconds). It now sayswas String (seconds). injectleft a double space (json) {) when it turned an=>fromJson into a block.- The CLI header boxes were misaligned.
Docs #
- README starts with a one-minute quick start.
1.1.1 #
- LICENSE: copyright holder is now the full name (Loay Elhamaky). No code changes.
1.1.0 #
First release on pub.dev.
Breaking #
- Annotations renamed so they no longer clash with other packages:
JsonKey→DtoKey(json_annotation),Required→DtoRequired(package:meta / Flutter),NullDefault→DtoDefault. - Removed annotations and options that never did anything:
NullHandling,DtoLog.className,JsonKey.fromJson/toJson/includeInToJson/includeInFromJson,NestedDto,EnumField,DateFormat(clashed with intl),DateTimeFormat. Enums, nested classes, lists andDateTimeare detected from the field type. - A missing key is now reported as
? not in response(warning) instead of· null, unless the reader has a default (safeIntOr,@DtoDefault, ...), which stays quiet. - A value that can't be converted is now reported as
✗(error) instead of· null.
Fixed — runtime #
DtoLogLevel.noneprinted everything. It now prints nothing (parse,logJson,.logged()).- A
fromJsonthat throws left its session on the stack forever. It is now logged asthrew ..., cleaned up, and rethrown. safeListthrew aTypeErroron a non-map item. Bad items are now skipped and logged.safeObjectrejectedMap<dynamic, dynamic>(e.g. from Hive). It is now accepted.safeListOf<int>failed the whole list for one bad item. Items are now coerced like single values ("1"→1) and bad ones are skipped and logged.safeIntOr& co. logged a null even though a default was given.asDateTime("1704067200")returned the year 170411. Digit-only strings of 10+ characters are now Unix timestamps;"20240115"still parses as a date.asInt("NaN"),asInt("Infinity")andasInt(double.nan)threw. They now fail safely.- Timestamps beyond
DateTime's range threw aRangeError. They now fail safely.
Fixed — JSON → Dart generator and CLI #
- Keys like
class,user-name,1stor Arabic text produced code that didn't compile. Names are now valid, unique Dart identifiers (class_,userName,field1st,field,field2); JSON keys stay unchanged. - Keys containing
',$or\broke the generated string literals. --required(allNullable: false) generatedint id = json.safeInt(...), which doesn't compile. Required fields now throw aFormatExceptionwhen missing or invalid.--no-loggingremoved the import that thesafe*calls need.- List item types used only the first item (
[1, 2.5]→List<int>). Every item is checked now; lists with nulls getList<int?>. - A list of objects used only the first object's keys. Keys from all items are merged.
- Singular names:
status→Statu,quizzes→Quizzand similar are fixed. - More than 20 fields generated
Object.hash(...)with too many arguments. - An empty object
{}produced adynamicfield read withsafeString. It is nowMap<String, dynamic>read withsafeMap. - Empty classes generated
Empty({})andcopyWith({}), which are invalid Dart. - A second nested class with the same name became
Dup_; it is nowParentDup. Nested classes never shadowdart:coretypes likeMaporList. - A field named
otherbroke the generated==. - The CLI wrote
out_buser.dartfor-o out_b(missing slash) in file mode. - The CLI now accepts a top-level array of objects and generates the item class.
- Interactive paste stopped at the first blank line inside pretty JSON. It now reads until the brackets close.
snakeToCamel('ID')gaveiD; leading acronyms are lowered now (ID→id,HTTPResponse→httpResponse).
Fixed — @DtoLog builder #
- Annotations are matched by package URL, so json_annotation's
JsonKeyis never picked up. - Non-nullable fields without a default didn't compile. They now throw a
FormatExceptionwhen missing or invalid;@DtoRequireddoes the same for nullable fields. - Enum fields were treated as nested classes (
Status.fromJson). Enums (and lists of enums) are parsed by name now and written as.name. DateTimewas written raw, sojsonEncodethrew. It is written as an ISO-8601 string now.- Default values: strings are escaped, lists/maps keep their content, enum
values work,
@DtoDefault(0)works ondoublefields, and a default of the wrong type is a clear build error. - Constructor arguments follow the real constructor (named and positional); a required parameter with no matching field is a clear build error.
- A nested class without
fromJsonis a clear build error instead of broken code. dynamicfields no longer show up as "not used by model".copyWith/ equality: 20+ fields useObject.hashAll; a field namedotherworks.- Verified to compile against analyzer 5.13.0 + source_gen 1.5.0 and analyzer 6.4.1.
Other #
DtoMock: field names match whole words (widthis not an id,shipping_addressis not an IP), dates are UTC so output is the same in every timezone, and list schemas like'items': [{'id': 'int'}]are supported.injectreports why each method was skipped (already logged / in a comment / unsupported shape).- The example no longer imports Flutter (it had 44 analyzer errors in a pure Dart package).
- Added LICENSE, CHANGELOG, .gitignore; removed the
yournamehomepage placeholder.
1.0.0 #
- Initial version.
