I’m migrating an ORM away from using
JSON.mapping and have a situation where I want to ignore fields when serializing or de-serializing selectively.
Currently there is the
@[JSON::Field(ignore: true)] but would be nice to be able to configure this for either direction.
deserialize: false /
serialize: false where they both default to true.
Happy to make a pull request if there is interest
That would be a breaking change so I don’t think we can do it.
Why do you need it just in one way?
A common scenario that comes to mind is user registration. I.e. you would want to be able to POST:
And the response should be:
I.e. allows an application to deserialize the password, but then doesn’t expose it again.
In that case you can have two objects, one with the password property, one without it.
But yeah, if we want to add it maybe we can have:
true, both serialize and deserialize are ignored, and it has precedence over the other two
true, only ignores on serialization
true, only ignores on deserialization
What do you think?
@Blacksmoke16 that is the exact situation where this came up.
@asterite I don’t think it would be a breaking change, totally in support of
ignore_deserialize I think it would be super useful.
@stakach Great! Feel free to send a PR, though there’s no guarantee it will go in (as usual).