Hi, I have already posted the question at SO (http://stackoverflow.com/questions/33735036/genson-caching-of-bean-accessors) but have not got an answer yet. This is fairly urgent so it would be excellent if we could find a solution to this soon.
I have recently upgraded to Genson 1.3 and I am not 100% sure if this issue is new or not as previously I patched the 0.98 version to make it work.
Context
We are using our own implementation of the BeanMutatorAccessorResolver. This is so that we can dynamically decide whether a property should be serialized or not. Basically we have integrated Genson into our generic jersey REST API interface. Genson does all the serializing and deserializing. When doing a GET requests it is possible for a user to pass fields in the URL in order to filter those he specifically needs (especially for large objects this is necessary where you only need 3 fields or so for displaying a table overview). For example: ?fields=field1, field2, field3. We then know in our implementation of BeanMutatorAccessorResolver exactly which fields to serialize and which ones to ignore. This is mainly intended for speeding up requests and parsing as we are then working with less data.
Problem
Unfortunately it seems that once Genson has read in all the fields via reflection or whatever, it caches that. This would be no problem if we were always requesting the same fields. Unfortunately on some occasions we need more fields then before, but because Genson does not visit our BeanMutatorAccessorResolver a second time it only returns the few fields that it has already cached.
Is there anyway around this?
--
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 http://groups.google.com/group/genson.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/6a3a965b-c679-418a-b05a-cb7012e0bbe2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/22cbe2a1-d478-47c0-aa5c-c1881e618e68%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/1c8ba180-a3b8-442a-9538-b7d3327c1527%40googlegroups.com.
protected <T> BeanDescriptor<T> create(Class<T> forClass, Type ofType, BeanCreator creator,
List<PropertyAccessor> accessors, Map<String, PropertyMutator> mutators, Genson genson)
{
return new DefaultBeanDescriptor<T>(forClass, getRawClass(ofType), filterPropertyAccessors(accessors), mutators, creator, genson.failOnMissingProperty());
}
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/1f6e5ea3-e82a-4188-abc9-dfd7501887bf%40googlegroups.com.
if (!isIgnore(accessor.getName()))
accessor.serialize(obj, writer, ctx);
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/ff2c637b-518d-4780-b7af-b7200df06171%40googlegroups.com.
UrlQueryParamFilter filter = new UrlQueryParamFilter();
Genson genson = new GensonBuilder().useRuntimePropertyFilter(filter).create();
new ResourceConfig()
.register(new GensonJaxRSFeature().use(genson))
.register(filter);
Please let me know if it works well for your use case as basically this is what you have described above.
Cheers,
Eugen