This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15791|Reply: 1

[Source] Jackson common error solutions

[Copy link]
Posted on 1/14/2019 4:23:10 PM | | |
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.itsvse.es.models.CarPosition` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

Cannot construct instance of `com.itsvse.es.models.CarPosition$Point` (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor
Solution:

The class adds a constructor as follows:


com.fasterxml.jackson.core.JsonParseException: Unexpected character ('' (code 65279 / 0xfeff)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')


Error causes:

The txt text file I read in Java isUFT-8 BOM encoding format resulted inof, meConverting a file file to utf-8 works fine! But since I have too many files, I can't manually convert each one to utf-8 format!

citation

EF BB BF54 68 69 73 20 69 73 20 74 68 65 20 66 69 72 73 74 20 6C 69 6E 65 2E

? This is the first line.

54 68 69 73 20 69 73 20 73 65 63 6F 6E 64 20 6C 69 6E 65 2E

This is second line.

The "EF BB BF" in the red part happens to be the BOM encoding of the UTF-8 file, which shows that Java did not correctly handle the BOM encoding of the UTF-8 file when reading the file, and treated the first 3 bytes as text content.


Solution:

maven references the following package:

Read the txt file code as follows:

I tested whether it was reading a UTF-8 BOM file or a UTF-8 format file, it was successfully converted to a UTF-8 format file, and the deserialization was successful!

One last word, no fastjson again! When encountering Alibaba's open source, if it is not the difference in advantages, don't take a detour.




Previous:2018 Wang Wenjun Google Guava practical video tutorial
Next:BOM prefix issues encountered when reading Unicode files (UTF-8, etc.) in Java
 Landlord| Posted on 1/15/2019 9:34:36 AM |
Encapsulated Jackson tool class:

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com