0

Is it possible with Genson to conditionally serialize an object property at runtime? In other words to include/exclude a property at runtime due to a condition?

I've read of a RuntimePropertyFilter in the doc but no examples on how to use it.

Thanks in advance!

Myrdivar
  • 145
  • 2
  • 10
  • Here is an example https://github.com/owlike/genson/blob/master/genson/src/main/java/com/owlike/genson/ext/jaxrs/UrlQueryParamFilter.java. Can you describe the kind of logic you would have to decide if a property should be ser/de? – eugen Jan 03 '17 at 21:35
  • The deserialize part is always on the complete object but I have a boolean during runtime that will tell me if I have to serialize the complete object or only a part of it. – Myrdivar Jan 04 '17 at 07:41
  • is the Boolean value inside the object being ser or somewhere outside (so you know its value before starting the serialization)? If this is the case you can implement it with a runtime property filter. Otherwise you probably want a custom serializer. – eugen Jan 04 '17 at 08:57
  • The boolean condition is outside so the RuntimePropertyFilter is what I believed could work. Do you know an example use of it? – Myrdivar Jan 05 '17 at 07:56
  • Click the link in my previous comment. This is an implementation that currently exists in Genson for jaxrs apps. You can inspire your self from there. – eugen Jan 06 '17 at 19:53

0 Answers0