The story background

A friend asked me on wechat that when Feign was called, the service provider had a result, but the value of this field was lost on the caller’s side. I felt incredible. If all the values were missing, it might be an error or something.

But the value of a field is missing, which is a new case. The following figure shows the information obtained by the caller with the nickname value missing.

Feign internally checks whether the data is received

If the service provider has a value and returns it, then the only problem is inside Feign, suspected to be internal decoding, and can only be found by debugging the code.

In the org. Springframework. Cloud. Openfeign. Support. SpringDecoder the decode method in the class to check the data after decoding exactly have lost, found that no longer exists.

Since it’s gone after it’s decoded, what about before it?

Use the following code to see if the data is lost before decoding:

IoUtils.toString(new FeignResponseAdapter(response).getBody(), "utf-8")
Copy the code

At this point, the cause of the problem is basically found. The data obtained from the server must be fine, and we see that it does exist, and then it disappears as soon as it is decoded.

Decoding the screening

But decoding is nothing special, just using HttpMessageConverter for data conversion. At the very bottom, ObjectMapper just converts strings into objects, just to see if there’s anything wrong with the Json conversion.

Finally in com. Fasterxml. Jackson. Databind. Deser. BeanDeserializer# deserializeFromObject found problems, nickname this field can’t find, is estimated to be ignored.

Then open the corresponding entity class and find @jsonIgnore above the field. If you start by looking at the received entity class then you can find the problem directly, at first did not expect this, but from the framework source code to find the problem step by step is more interesting, also in line with the logic of step by step pit.

About the author: Yin Jihuan, a simple technology lover, the author of Spring Cloud Micro-service – Full stack Technology and Case Analysis, Spring Cloud Micro-service Introduction combat and Progress, the founder of the public account Monkey World.

If you are interested, you can pay attention to my wechat public number, Simtiandi, and read more technical articles for the first time. I also have some open source code on GitHub github.com/yinjihuan