Java – org.codehaus.jackson.JsonParseException: Unexpected character (‘/’ (code 47))

hashmapjavajson

I have a file that contains a HashMap customer list in json format.

Like this:

{"Davide":{"name":"Davide","cf":"FRCDVD","pi":"1234",
    "telephone":"333","website":"www","sector":"Student","address":"Rome"}}

This is just a one customer of list.
Everytime the controller is called I want to take datas from the file and convert them into HashMap list.

I tried to do this with:

HashMap<String, Customer> listCustomer = new HashMap<>();
listCustomer = new ObjectMapper().readValue(pathCustomerFile, HashMap.class); //This line gives me error

I got this error:

org.codehaus.jackson.JsonParseException: Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)

How can I do that?

Best Solution

I had this issue recently. I was trying to pass a path (in the form of a string) to readValue. You need to pass it either a string to parse, or a file object. Based on your variable nameI think you may have passed it the path to a file.

(Basically, it's reading the '/' in the file path and throwing errors on them.