Skip to content

feat: Add JsonSerializable(createJsonMeta)#1164

Merged
kevmoo merged 16 commits into
google:masterfrom
rrousselGit:add-json-meta
Jun 28, 2022
Merged

feat: Add JsonSerializable(createJsonMeta)#1164
kevmoo merged 16 commits into
google:masterfrom
rrousselGit:add-json-meta

Conversation

@rrousselGit
Copy link
Copy Markdown
Contributor

As discussed before, this adds an option for generating a constant Map of property name: json name

fixes #972

///
/// This constant can be used by other code-generators to support features
/// such as [fieldRename].
final bool? createJsonMeta;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"meta" is pretty vague here. Maybe createFieldMap? Let's talk before you start rewriting everything...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xFieldMap sounds good to me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

assert(config.createJsonMeta);

final buffer =
StringBuffer('const _\$${element.name}JsonMeta = <String, String> {');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful using element.name – if it's already private you'll end up with double _ which makes analyzer sad.

I have a helper around here somewhere for this"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I haven't seen another util for this

Comment thread json_serializable/test/integration/json_meta_example.g.dart Outdated
@kevmoo
Copy link
Copy Markdown
Collaborator

kevmoo commented Jun 27, 2022

still hacking on the failures @rrousselGit ?

@rrousselGit
Copy link
Copy Markdown
Contributor Author

Indeed.

I don't quite understand why the CI says generated code is outdated. It isn't for me locally

@kevmoo
Copy link
Copy Markdown
Collaborator

kevmoo commented Jun 27, 2022

@rrousselGit – need to do another rebuild. After a pub upgrade?

Comment thread json_annotation/pubspec.yaml Outdated
@rrousselGit
Copy link
Copy Markdown
Contributor Author

Looks like it's good now 😄

@kevmoo kevmoo merged commit 25c6138 into google:master Jun 28, 2022
@kevmoo
Copy link
Copy Markdown
Collaborator

kevmoo commented Jun 28, 2022

good job on this!

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

Successfully merging this pull request may close these issues.

Expose utilities to allow other code-generators to know how an object is serialized

2 participants