Friday, February 15, 2019

Jackson ObjectMapper: Unexpected character: was expecting double-quote to start field name

If you are running into the following error message, you need to configure your ObjectMapper to allow for unquoted field names. You can accomplish this in a single line:

mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);

Here's a full example of the code:

import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.ObjectMapper;

public class Example {
    public static void main(String[] args) {
       ObjectMapper mapper = new ObjectMapper();
       mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    }
}