Hello all,

I am spinning my head for two days now in the code of the Jackson Json 
Serializer and I guess it is now time to ask somebody.

I am building REST-APIs with Spring boot and as they are supposed to be 
accessed by different applications and they don't always require the whole 
set of data for a resource, I wanted to implement the possibility to 
specify the fields I am interested in on the request. Basically this is a 
fine grained projection. 
For example, imagine I have a Person that has a firstname and lastname 
property as well as an address with street, zip and town I want to be able 
to request a person like this:

http://myService/people/1234?resultFields=firstname,lastname,address.town

In order to achieve this, I looked at the different options and a JsonView 
is actually too static for this approach. According to the documentation of 
Jackson, a PropertyFilter should do the trick as it allows dynamic 
filtering per serializer call and indeed it was providing me the basic 
functionality that I required. The remaining piece of the puzzle is now how 
I can deal with inner objects. In my example above this would be the 
"address.town". The method

public boolean include(PropertyWriter writer)

only provides me with the name of the actual property, so either "address" 
for the property on the Person or "town" for the property on the address. 
But what I need is the context information based on which I can construct 
the full path.

I looked at 
public void serializeAsField(Object pofo, JsonGenerator jgen, 
SerializerProvider provider, PropertyWriter writer)

that seems to be called before the include method and I saw that the 
JsonGenerator has a property called outputContext which seemed like the 
right thing to generate the path and put it on the request attributes in 
order to retrieve it again in the "include" method but unfortunately the 
information on the context is not updated during the invocations. The 
BeanSerializerBase is just putting it once and then iterates over all the 
properties.

Therefore my question: Does anybody have a good idea on how to solve this 
or can push me in a different direction in order to achieve what I want?

I appreciate every help.

Cheers
Patrick

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to