bizzabo / play-json-extensions

+22 field case class formatter and more for play-json
http://cvogt.org/play-json-extensions/api/
Other
195 stars 47 forks source link

Make OptionValidationDispatcher constructor public #30

Open psttf opened 8 years ago

psttf commented 8 years ago

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 to None. I want to have None 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 own OptionValidationDispatcher passing a custom function that works with LookupResult.

cvogt commented 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?

psttf commented 8 years ago

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.

cvogt commented 8 years ago

I am happy to accept a PR making it public :).

psttf commented 8 years ago

Ok!

cvogt commented 8 years ago

If you also add a test case which basically demonstrates your use case, that would be awesome :)

psttf commented 8 years ago

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