Freezed: [Question] dart-json-mapper

Created on 8 Mar 2020  ·  11Comments  ·  Source: rrousselGit/freezed

Hi there,

We use dart-json-mapper as our Json serializer.
Since Freezed already support decorator, I'm wondering how difficult it will be to add it next to json_serializer ?

Regards

Ps: Issue#83 might also solve it, but in a less optimal manner.

question

Most helpful comment

The two package at this time don't mix correctly (Concrete exemple on the screenshot).
My point was see if it was possible to resolve this.

I personally think we should have the choice to use the serializer we want.

All 11 comments

Hi

I do not really understand. What's the purpose, and what do you need?

I'll try to give more context.

While Freezed will not generate your typical fromJson/toJson by itself, it knowns what **json_serializable** is.
Making a class compatible with json_serializable is very straightforward.

I would like to be able to do the same with https://github.com/k-paxian/dart-json-mapper witch we already deploy on my project.

I tried to integrate both Freezed with Dart_json_mapper below :
Screen Shot 2020-03-09 at 12 59 03 AM

Out of the build, there is several errors in the generated file :

"The name 'JsonSerializable' is defined in the libraries package:dart_json_mapper/src/model/annotations.dart' and 'package:json_annotation/src/json_serializable.dart'."

Hope this make sense.

But what does that bring you over using json_serializable?

Enum, inheritance, and custom types converter are features that stand out for me.

Could you extend on this with concrete example and how that would related to freeze?

The two package at this time don't mix correctly (Concrete exemple on the screenshot).
My point was see if it was possible to resolve this.

I personally think we should have the choice to use the serializer we want.

Freezed does not support dart-json-mapper, so it not working is expected.

The question is: what would be the benefits of having Freezed support it?

Not sure how to respond to be honest. I could state that is a good thing to be agnostic, so it broaden the possibility and as stated before let the users choose what they want.

On a personal note, I wanted to add Freezed to my project but already have my serialization handle with dart-json-mapper. Like your projet, it provide a convenient way for us to handle a purpose (Certainly the Java-Jackson parity that got our attention at the beginning)

Finally, I don't expect of you to support dart-json-mapper, but it will be great if both package were not incompatible.

If you still think this is not needed/useful, you can close the issue with no harm done. 🤙

I'm not against it. But the work to be done would be quite important. As it stands, I don't see why I would work on that when I can do something else more useful.

The best I can do is remove the hard dependency on json_annotation and require people to import it themselves (which is not a bad idea anyway).

This would solve the conflict (although you can fix it yourself through `import 'freezed_annotation/...' hide JsonSerialization'

@rrousselGit I also want to combine these both libraries.
I tried to put the @jsonSerializable on the constructor created by freezed. It passes the decorator to generated constructor.

But, the problem is, the generated constructor is private (starts with _) and the reflectable file created by dart-json-mapper can't simply access that.

Closing as I have no plan to work on this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

linhdogg picture linhdogg  ·  4Comments

samandmoore picture samandmoore  ·  4Comments

jonasbark picture jonasbark  ·  3Comments

narcodico picture narcodico  ·  6Comments

freezed picture freezed  ·  4Comments