Uh oh!
There was an error while loading. Please reload this page.
[Dart-Dio-Next]#9082 Add json_serializable serialization option - #9980
Conversation
kuhnroyal
commented
Jul 20, 2021
Nice job! Was hoping someone gets the ball rolling on this and prepared the codebase somewhat. |
jbrisko
commented
Jul 21, 2021
I am also very interested in this. I would love to test it. Migrating our project to built_value would be super inconvenient. |
agilob
commented
Jul 26, 2021
I think this should be new generator extendin dartdio.java not a config flag on dio, it's a big change in generator and there's a lot of potential for generator conflicts and bugs in generated code if they life together. If you decide to keep them together under one generator at least add tests for dio-json_serialisabable |
| strict-raw-types: true | ||
| strong-mode: | ||
| implicit-dynamic: false | ||
| implicit-dynamic: true |
There was a problem hiding this comment.
no sure that's wanted, why changing this ? if it's a requirement for the lib please do it only for it
There was a problem hiding this comment.
Sorry this wasn't meant to be committed. The code generated by json_serializable includes a lot of implicit dynamic and so this option throws up a lot of errors in the generated code.
How do we feel about excluding *.g.dart instead, so only the generated code is excluded? Building on that, only exclude generated code if we're using json_serializable?
There was a problem hiding this comment.
to me doesn't make sens to analyze generated code, so I'm fine to exclude *.g.dart for all
There was a problem hiding this comment.
I am not sure you can exclude files from strong-mode. I thought this only works for the lints. But if it works then go for it.
There was a problem hiding this comment.
This seems to work? google/json_serializable.dart#557 (comment)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jaumard
commented
Jul 26, 2021
We will not make a new generator each time we want to change the serialization library. It doesn't make sens and will be a nightmare to maintain. It need to be done properly to avoid conflicts and bugs, here it's on different files for the most parts so it's fine. But sure it would be better with tests. I'm interested to use freezed at some point so I really think the config flag is the way to go to centralize all the Dio related stuff. |
kuhnroyal
commented
Jul 26, 2021
I disagree, we should not start a new generator. We end up with no one maintaining it. I prepared the dart-dio-next generator exactly for this use case. And yes we need a sample and tests :) |
MichaelMarner
commented
Jul 26, 2021
Hey thanks for the feedback so far. Just to give an indication of where I'm at with this. We spent most of last week migrating our mobile app from Swagger/codegen to this branch of Dart-Dio-Next. So far all appears to have worked well with no bugs introduced to our app. The mobile app is scheduled for a release next week, and so this week is mostly internal testing and QA. So far though we're happy with the code this branch is generating. Once our app update has been released I'll have a bit of time to come back and tidy up this PR. Agreed tests and samples are needed to ensure both this works, and that it doesn't break the built_value serialisation. I pushed this PR early as a draft just so people can be aware it's happening and to provide early feedback. Cheers |
Hey @MichaelMarner - I had some time so I had a go at adding a sample project and some tests to your changes. It uncovered a couple of issues in the templates which I've addressed wherever possible however I'm unsure how to progress it any further as I'm not familiar enough with this Java/OpenAPI/maven to wire up the automated testing (although I gave it a go based on the existing projects). Happy to keep pushing it forward if I can get some feedback on it. |
kuhnroyal
commented
Aug 13, 2021
Good work, i'lll try to checkout the sample and see if I can help. One thing I noticed is the use of mutable models. I would like to see immutable models by default and if anyone requires mutable models, we could add a flag for it. Can you merge master when you get a chance? |
zbarbuto
commented
Aug 15, 2021
Thanks @kuhnroyal - merged master into my branch but makes the PR into Michael's fork pretty noisy so might be better to just rebase and cherry pick once happy with it. |
MichaelMarner
commented
Oct 26, 2021
Hey so it turns out that real work kind of took priority over this PR, but I've just made a few changes to fix some things up:
|
Hi, I'm using a version before these latest commits and was relying on mutable models (when sending back to the rest API for creation/update). I'm quite new with dart, is there a different way I should be doing this? ... or could properties be made optionally final? |
MichaelMarner
commented
Nov 3, 2021
Hi @elliots all properties are named parameters in the model constructor, so you can set them that way: newMyModel(property1:"asdf", property2:"etc");I can look at adding an option for optional |
elliots
commented
Nov 3, 2021
I'm updating individual properties on the model as the user performs actions, if they are final I would need a second model for the ui that I then use to create the values to post back to the server. Worth adding an option if you think others would do similar, but I've forked with the 'final' removed for my use so no worries. |
ayushin
commented
Mar 13, 2022
is this still active? how about adding https://pub.dev/packages/freezed |
MichaelMarner
commented
Mar 15, 2022
We've been using this in our production app since August of last year without any issues. At this point I think it's ready to go but I'm not sure what the next steps are, as I'm new to this project |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
needs includeIfNull to be used in conjunction with required. If field is required, then null value must be included
There was a problem hiding this comment.
I believe I have addressed this now
There was a problem hiding this comment.
enum parameter can have a value, so field FIELD_1 can be represented by field-1 and so field-1 must be mapped to FIELD_1
There was a problem hiding this comment.
This supported from 4.2.0 https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonEnum/fieldRename.html
There was a problem hiding this comment.
Latest commits have fixed up generation of enums, and I've used @JsonValue() to specify the enum values
Please add sample project for this generator. |
Please target current master, which will be released as v6.0.0. By the way, shall we replace cc @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08) |
Enum fixes and Maven module
MichaelMarner
commented
Apr 14, 2022
Have merged your PR back into this |
kuhnroyal
commented
Apr 14, 2022
I'll check later for the failures, must have a typo in the POM. |
* add a beta hint to json_serializable option
ayushin
commented
Apr 17, 2022
Is this not a good time to add an option for freezed as well? |
kuhnroyal
commented
Apr 17, 2022
If you write it sure :) |
MichaelMarner
commented
Apr 19, 2022
I think it might be a bit of scope creep to also introduce freezed to this PR. I'd really like to see this merged so I don't have to keep rebasing against master as new changes come in. It will be easy enough and cleaner to extend this branch to include freezed as an option later on. My 2c anyway. |
kuhnroyal
commented
Apr 20, 2022
Yea definitely not as part of this PR. |
Update docs and fix wrong maven module
kuhnroyal
commented
Apr 22, 2022
Needs a merge again |
kuhnroyal
commented
Apr 25, 2022
@MichaelMarner Can you merge again please, want to get this in |
c28c5b3 to
554a63eCompare554a63e to
67ec4edCompare3066c2e to
a016b88CompareSorry, was a long weekend in South Australia and I was out of town. Have merged
|
1266195 to
cf5ceefCompareUh oh!
There was an error while loading. Please reload this page.
kuhnroyal
commented
Apr 27, 2022
Big thanks @MichaelMarner ! 🤘 |
MichaelMarner
commented
Apr 27, 2022
Woo! Thanks for your patience everyone. |
This is a WIP/PoC to add
json_serializableas an alternative tobuilt_valuein the Dart-Dio-Next generator.For context: We would like to migrate our Flutter app to full null safety, and so we are migrating from the old Dart generator to Dart-Dio-Next.
We have found that moving from models with to/fromJson methods to using built_value has made the job of migrating bigger and riskier than we'd like. We need to rewrite large chunks of our existing persistence layer and other parts.
Adding
json_serializableas an option has mostly involved reworking existing templates in the old Dart generator to generate null safe code.Fixes#9082
@swipesight @jaumard@josh-burton@amondnet@sbu-WBT@kuhnroyal@agilob
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.For Windows users, please run the script in Git BASH.
master,5.3.x,6.0.x