mobxjs / serializr

Serialize and deserialize complex object graphs to and from JSON and Javascript classes
MIT License
766 stars 52 forks source link

can I use `object()` without passing argument #66

Closed chengjianhua closed 6 years ago

chengjianhua commented 7 years ago

sample:

@serializable(list(object())) dates = [];

The property dates is an array of object shapes like { from: 36000, to: 42000 }. I want to serialize dates, but I don't like to abstract the date object into a class, it's tiresome and not necessary ...

Can we remove the required argument for object(), leave it empty that means for JSON.stringify it.

I can do this myself in my project, but I think this is a common case and it make sense, besides, I don't have to be compelled to dream up a new api name for this ...

What do you think about this ? @alexggordon

mweststrate commented 7 years ago

In mobx-state-tree the frozen type is used for this, which basically means: use this value verbatim in (de)serialization. I think something like that could work here as well (frozen might not be the best name though)

chengjianhua commented 6 years ago

@mweststrate So the suggestion you give is to add a type like frozen to cover this requirement ?

Fine, it's not a bad idea. Maybe we can name this type json ( intuitive 🙄 ) or direct and so on ...

alexggordon commented 6 years ago

@chengjianhua what about a plain type? The issue with frozen is that it's not actually frozen. As far as a json type, I would expect that this could be used with something that isn't actual json, like if you have a date or something that you don't want deconstruct.

chengjianhua commented 6 years ago

@alexggordon Sorry for replying to you lately ... It's seems that we have reachd a consensus that we need such a type.

Now that you expect that this type could be used for not only json, but also a date ( means Date() ? ) and something others, what about we name this raw. I think this is semantic enough to understand it and use it in many cases.

If you think this is ok, I'm happy to have a pull request for this.

alexggordon commented 6 years ago

Actually I do like the raw better than plain. That's a good word.

And sure, if you want to PR should be pretty easy. It's just primitive without validations I think.

chengjianhua commented 6 years ago

@alexggordon Yep ~ you are right 👍

I have implemented this in my project ...

alexggordon commented 6 years ago

merged in f5d6ac3

cervengoc commented 6 years ago

@alexggordon We'd need this exact feature too. Could you please give us an estimate on when you're planning to push a new release? Thank you.

alexggordon commented 6 years ago

@cervengoc I'll deploy the new version right now

alexggordon commented 6 years ago

@cervengoc I've published the raw type in version 1.2.0

cervengoc commented 6 years ago

@alexggordon Thank you very much for the quick action.