Thanks Tatu, but how do I read it back when I send this as part *exception 
*JSON 
body? It seems like when if read the body with 
HttpStatusCodeException.getResponseBodyAsString(), it contains all sort of 
JsonNode data rather than the actual data that I send back from the Rest 
producer.


On Tuesday, May 21, 2019 at 7:08:22 PM UTC-4, Tatu Saloranta wrote:
>
> On Tue, May 21, 2019 at 3:57 PM Uzh Valin <[email protected] 
> <javascript:>> wrote: 
> > 
> > Ok, but how does Jackson know which custom mapper to call if we are 
> simply putting obj.getFirstProperty() in the response map? I know need one 
> value and would want the serializer to ignore all other properties 
> regardless whether they have been initialized with default values. 
>
> It doesn't, but what I am saying is that your approach will not work as 
> shown. 
> If you add String values, they will be JSON Strings and must be 
> escaped. That's how Strings are handled -- otherwise Jackson would 
> have to somehow re-parse String into JSON, and then go back to 
> serializing contents, adding significant overhead that is not usually 
> needed. Assuming that String was valid JSON; if not it would either 
> have throw exception, or quietly determine it has to be used as-is... 
> or something. 
>
> If you want to apply different rules there are a few ways you could 
> achieve that -- custom serializers are one way -- or you could 
> serialize-as-String-then-deserialize if you want to apply filtering. 
> Perhaps latter is the way to go. 
>
> In fact, you could probably use something like: 
>
> JsonNode node = mapper.valueToTree(inputValue); 
> results.put(key, node); 
>
> which would convert from POJO into JsonNode -- and this does use 
> serialize() methods, filtering, but with less overhead -- and then add 
> JsonNode as value to be serialized by "parent" mapper. 
>
> I think this might achieve what you are attempting here? 
>
> -+ Tatu +- 
>
> > 
> > 
> > On Tuesday, May 21, 2019 at 2:40:27 PM UTC-4, Tatu Saloranta wrote: 
> >> 
> >> Just one question: 
> >> 
> >> 
> >>> 
> >>>         responseBody.put("firstProperty", 
> serializeFirstProperty(obj.getFirstProperty())); 
> >>>         responseBody.put("secondProperty", 
> serializeSecondProperty(obj.getSecondProperty())); 
> >>>         responseBody.put("thirdProperty", 
> serializeThirdProperty(obj.getThirdProperty())); 
> >> 
> >> 
> >> Why do you serialize values? That is where "double-escaping" comes: you 
> are adding JSON String within content to be JSON serialized. Just add 
> values as is 
> >> 
> >>    responseBody.put("firstProperty", obj.getFirstProperty()); 
> >> 
> >> and contents would get serialized just once. 
> >> 
> >> -+ Tatu +- 
> >> 
> >> 
> > -- 
> > 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] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jackson-user/e9420cec-0ddb-4af4-bfc7-1383bede4920%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/ddd137c4-0f74-4976-9a86-64a9f7f1daba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to