GensonBuilder.exclude() method not working

24 views
Skip to first unread message

tim wilkins

unread,
Jul 5, 2016, 10:47:42 AM7/5/16
to Genson user group
Hi,

I'm trying to exclude certain fields from my case classes using the GensonBuilder.exclude() method. 

I found this example:

http://stackoverflow.com/questions/29485782/how-do-you-exclude-fields-in-jackson-json-serialisation-scala

but when I try to implement it as here


the 'amount' field is not excluded as I require.

What am I doing wrong (or is there an issue)?

FYI: Scala 2.11.7, "com.owlike" %% "genson-scala" % "1.4"

Thanks,

Tim

Eugen Cepoi

unread,
Jul 5, 2016, 11:47:52 PM7/5/16
to gen...@googlegroups.com
Hi Tim,

Thanks for reporting this and the clear example. Indeed this is a bug in Genson.

Here we define a property resolver that will be used before the standard and user defined ones.
From a quick look it looks like there is an easy fix. It would consist in registering the case class property resolver inside the configure method of ScalaBundle and just use the passed propertyResolver inside createBeanDescriptorProvider (the code in your gist would remain the same).

I tried it out with your gist and it solves the problem. Would you mind forking the project, try it against some of your use cases and open a pull request with those changes/report any issues?

Thank you!
Eugen


--
You received this message because you are subscribed to the Google Groups "Genson user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genson+un...@googlegroups.com.
To post to this group, send email to gen...@googlegroups.com.
Visit this group at https://groups.google.com/group/genson.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/ece63d0e-5fd8-4f81-b10e-d298ab312da7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tim wilkins

unread,
Jul 12, 2016, 4:17:07 AM7/12/16
to Genson user group
Hi Eugen,

I've implemented the fix that you suggested and the exclude filters now work as expected.

As part of my unit test that I've added to the project for exclude filters I thought I'd test the 'rename' methods but these don't seem to work either.

I'm not clear as to why your fix works so I'm not sure if I need to do something similar to get 'rename' to work.

Here is the implementing commit on my fork of the project:


If you can see what's missing to make 'rename' work let me know and I'll add it before submitting the pull request.

Thanks for your help.

Tim

Eugen Cepoi

unread,
Jul 12, 2016, 1:37:23 PM7/12/16
to gen...@googlegroups.com
Hey Tim,

Try to do the rename before registering the ScalaBundle (even though in the javadoc we state that most customizations should be done afterwards).
This is strange as there is no reason for it to not work when defined after the bundle...this is very likely a tricky bug. I opened that issue https://github.com/owlike/genson/issues/101 to tack my progress.

BTW as I was unsure if you were planning to add a fix, I went ahead and implemented it here.

Please let me know if you encounter any strange things when using the Scala Bundle. Ideally I hope to have all the features that exist in the java version of Genson work well for Scala too...

Thank you!
Eugen


tim wilkins

unread,
Jul 13, 2016, 4:19:57 AM7/13/16
to Genson user group
Thanks for the work-around Eugen. 

I'll watch the issue you created, let me me know if I can help in any way.

Thanks for all your hard work on this project, it is very much appreciated!

Tim
Reply all
Reply to author
Forward
0 new messages