hiranthaR / Json-to-Dart-Model

Json to Dart Model extension can convert JSON objects into Dart data classes. It supports pure Dart class conversion, Flutter-recommended JSON serialization using annotations, Freezed support, Effective Dart:Style, and many more features. Currently, it has more than 135,000 installs.
https://marketplace.visualstudio.com/items?itemName=hirantha.json-to-dart
MIT License
93 stars 18 forks source link

Json Field case are not respected #12

Closed apgapg closed 3 years ago

apgapg commented 3 years ago

Describe the bug

Suppose a json look like this:

{
    "FieldA":"abc"
}

The output freezer class variable would become camelcase which will not correctly parse the field as it is in pascalcase. Ideally @JsonKey(name:'FieldA') must be there above this variable generated.

Additional context The problem lies in fixFieldName method in helper.dart which makes field name to camel case

iamarnas commented 3 years ago

@apgapg Hi, I was working on this right now to add json keys for Freezed class. But I see I'm too late :) after merging I will check if everything work well and correct if needs. Thanks for your opinion.

hiranthaR commented 3 years ago

@iamarnas is it ok to merge? I am not updated with flutter these days

apgapg commented 3 years ago

@iamarnas Sure. But I see only the name option can be utilized herein @JsonKey, others like defaultValue cannot be used here without user consent. Are there any other you planned to include in JsonKey except name?

iamarnas commented 3 years ago

@hiranthaR Hi, Is OK. Everything looks good.

@apgapg Hi.

Are there any other you planned to include in JsonKey except name?

Right now I am working with more accurate generating for deeply nested json files, it is more important right now. What about Freezed I have not more idea just trying keep it clean and thought fix better support for json, need more opinions from users. You opinion is welcom :)

iamarnas commented 3 years ago

@apgapg Hi,

Others like defaultValue cannot be used here without user consent.

It is possible to add default values ​​from the json file examples, most values ​​have some example values ​​to define value types. But Freezed has so many options that it is better to leave it to the users consent like you say. Anyway after generated classes, it is easy to edit. Just edit row and run builder.

iamarnas commented 3 years ago

@apgapg HI!

@iamarnas Sure. But I see only the name option can be utilized herein @JsonKey, others like defaultValue cannot be used here without user consent. Are there any other you planned to include in JsonKey except the name?

You asked about more futures :) The latest version 3.1.5 supports default values and required, more... All suggestions on how to improve code are welcome.