The package that Jackson used in Springboot was fasterxml. You can convert a string in JSON format to a Java object by using the following code:
New Com.fasterxml.jackson.databind.ObjectMapper (); Mapper.readvalue (String, JavaBean. class);
However, when we want to turn the string is this format will be an error, because this format is not the canonical JSON format:
{success:2,message: ' Certification has passed! The device is not added, please contact the airline. Device code: 1101 '}
The error message is:
com.fasterxml.jackson.core.JsonParseException:Unexpected character (' s ' (Code)): Was expecting Double-quote to Start field name
Fasterxml expects field names to be enclosed in double quotes, which is expected:
{"Success": 2, "message": "Authentication passed!" The device is not added, please contact the airline. Device code: 1101 "}
By contrast, it was found that the above string and the canonical JSON string have two different points, one is the field name is not quoted, the second is a single quotation mark. These are not standard JSON format notation.
The best solution, of course, is to turn string strings into the canonical JSON format, but for some reason, you have to use this format.
Solve:
New Com.fasterxml.jackson.databind.ObjectMapper (); // allows the use of unquoted field names mapper.configure (feature.allow_unquoted_field_namestrue); // single quote mapper.configure (feature.allow_single_quotestrue) is allowed; Mapper.readvalue ( String, JavaBean. class);
In addition to the allow_unquoted_field_names,allow_single_quotes there are other settings, useful to try.
Resolving string string to object JSON format error in Fasterxml