I am trying to write/read a simple class to a file using Jackson and I can't get read the file after I create it. I get
org.codehaus.jackson.JsonParseException: Unexpected character ('.' (code 46)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: java.io.StringReader@f2dec59; line: 1, column: 2]
My object is pretty straightforward; it's basically just a container for a HashMap. Here is the resulting JSON file that I checked out with JSONLint:
{
"quaternions": {
"10": {
"x": 0,
"y": 0,
"z": 0,
"w": 1,
"identity": true
},
"11": {
"x": 0,
"y": 0,
"z": 0,
"w": 1,
"identity": true
},
"12": {
"x": 0,
"y": 0,
"z": 0,
"w": 0,
"identity": false
}
}
}
The code I am using to read the file is as follows:
TypeReference<ZeroQuaternions> typeRef;
typeRef = new TypeReference<ZeroQuaternions>() {};
ZeroQuaternions readQuats = mapper.readValue("./zeroQuatTest.json", typeRef);
You have this error because jackson tries to deserialize ./zeroQuatTest.json
string instead of content of your file. Try to call
TypeReference<ZeroQuaternions> typeRef;
typeRef = new TypeReference<ZeroQuaternions>() {};
ZeroQuaternions readQuats = mapper.readValue(new File("./zeroQuatTest.json"), typeRef);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With