Home > Back-end >  About using fastjson generic tools TypeReference thinking
About using fastjson generic tools TypeReference thinking

Time:01-06

Recently took over a old project, an iterative development process using fastjson generic tools deserialization failure problems, will share with you the problem and prevent you from using the tool of students on pit, interface return type if you use the generic, in the use of TypeReference generic interfaces for the sequence, sometimes the sequence failed (for the current type jsonobject, rather than a class) analysis is as follows: the main reasons why
1. Interface returns on generic types (String or complex type) is specified, then TypeReference these types will be a one-to-one correspondence relationship in the form of key-value pairs in the Map, later again the same specified type, from the cache to read the Map information to find the corresponding type deserialization.
2. Interface if you do not specify a return type, TypeReference will read the default type of the parent to match (simple the default String type, complex type defaults to JsonObject), that is the reason why cause the failure of the sequence,
Conclusion: if you want to use TypeReference generic tools, all return to the interface used to specify a return type, to avoid the above problems,

CodePudding user response:

A bit, then I don't understand why you post must be put a few minutes,,,,,,,
  • Related