In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to solve the problem of jackson serialization and feign return value. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Jackson serialization and feign return value jackson note
Serialized / deserialized entity
a. There must be no parameter construction method.
b. Fields should have a set/get method
c. Fields that do not need serialization can be decorated with @ jsonIgnore
FeignClient return value problem
The type of the return value is not necessarily the same as that of the callee.
Such as:
The called party is
ResponseBody@RequestMapping ("test"); public Map test () {Map map = new HashMap (); map.put ("name", "zhangsan"); map.put ("address", "address"); return map;}
Caller:
@ FeignClient ("xxxx") public Interface xxService {@ RequestMapping ("/ test") Test test ();} / * the attribute corresponding to the entity class corresponds to the corresponding attribute in map. * / @ Dataclass Test {public Test () {} private String name; private String address;}
Another way is for the caller to receive it directly with string and then convert it himself.
Feign call exception, deserialization failure exception message is as follows
Nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `xxx` out of START_OBJECT token
Originally, I replaced the original message converter with the fastjson message converter. I thought I didn't replace it, so I tossed around for a while.
Later, when the fastjson message converter was removed, it still reported an error. I thought it should be the data returned.
The data returned by the control layer of the called service is consistent with the object of my deserialization. It should be that the called service uniformly wraps the returned data, resulting in the problem. Just remove the wrapper, or the deserialized object is the wrapped object.
I'm adding the headers attribute to the method mapping, the attribute value Keep-Original=Keep-Original, and removing the wrapper.
@ GetMapping (value = "xxx", headers = {"Keep-Original=Keep-Original"})
Finally, the problem was solved perfectly.
Thank you for reading! This is the end of this article on "how to solve the problem of jackson serialization and feign return value". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.