Open psttf opened 8 years ago
Shouldn't you be able to solve this problem by simply providing a custom Format for Option that maps empty strings to None instead of doing something involving OptionValidationDispatcher?
This approach will require that the field is present in JSON while I need the field to be optional. As I understand the fact that the field is present or not present is captured in the LookupResult
and OptionValidationDispatcher
allows to customize processing on this stage. Format
(or, more precisely, Reads
) allows to control only the processing of JsValue
that is obtained from LookupResult
if it is non-empty — no way to process the case when the initial LookupResult
is empty.
In my understanding OptionValidationDispatcher
gives an excellent opportunity to hack into the first stage of JSON processing (presence of the corresponding field), but unfortunately it is inaccessible due to private constructor. At the same time I cannot see any reasons for the constructor to be private.
I am happy to accept a PR making it public :).
Ok!
If you also add a test case which basically demonstrates your use case, that would be awesome :)
Sure!
On 20.09.2016 17:10, Jan Christopher Vogt wrote:
If you also add a test case which basically demonstrates your use case, that would be awesome :)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/xdotai/play-json-extensions/issues/30#issuecomment-248312565, or mute the thread https://github.com/notifications/unsubscribe-auth/AAriqwP_LvIY4TXUvl78wIChB6BH6Pb9ks5qr-lUgaJpZM4KADGZ.
Best regards, Pavel Shapkin p.shapkin@gmail.com mailto:p.shapkin@gmail.com
Is it possible to make
OptionValidationDispatcher
constructor public? I need to implement a format for a case class with optional fields and want to tweak the logic that sets fields toNone
. I want to haveNone
both when field is not found in JSON and when it is found but e.g. equals""
. I cannot find other ways of implementing this except instantiating my ownOptionValidationDispatcher
passing a custom function that works with LookupResult.