0

I am using JAVA 8 and I have a JSON file as below which am reading in a webapp:

 {
    "ecn": 1,
    "name": "Cummings",
    "dateOfBirth": "12/30/2017",
    "address": {
        "addressLine1": "322 Mill Street",
        "addressLine2": "Ramanna lane",
        "county": "Banashankari",
        "city": "Laworao",
        "state": "Harito",
        "zipcode": "RY3E4",
        "country": "Gardow"
    },
    "cuac": true,
    "occupation": "Engineer",
    "residence": "Ofcourse",
    "citizenship": "Gardowian",
    "registration": "asdf-1243",
    "type": "Individual",
    "businessDescription": "Mechanical Engineering parts",
    "parentingLevel": 5,
    "endPoint": "http://hello",
    "risks": [{
        "riskRating": 3,
        "riskCode": "234"
    }],
    "accountInformation": [{
        "accountNumber": 111,
        "routerNumber": 222,
        "nameOnAccount": "Raghuveer",
        "openDate": "12/20/2017",
        "dateLastAccessed": "12/24/2017",
        "closeDate": "12/25/2017",
        "product": "Engine",
        "balance": 123.123
    }],
    "balanceSummary": {
        "clientBalanceDetails": [{

                    "name": "Raghuveer",
                    "categories": [
                        {
                            "amount": 124,
                            "type": "Deposits"
                        }
                    ]
                }
        ]
    }
}

I am reading this from a util file with method :

public static byte[] readMe(InputStream obj) throws IOException {
        ByteArrayOutputStream baOStream = new ByteArrayOutputStream();
          ObjectOutputStream objOStream = new ObjectOutputStream(baOStream);

          objOStream.writeObject(obj); 
          objOStream.flush();
          objOStream.close();
          return baOStream.toByteArray(); 
    }
...
public static <T> T unMarshal(String json, Class<T> clazz) throws IOException, URISyntaxException {

        InputStream is = Convertor.class.getResourceAsStream("WEB-INF\\classes\\data\\info.json");
        byte[] jsonData = readMe(is);
        return  objectMapper.readValue(jsonData, clazz); //exception is thrown here
    }

My Maven dependencies are as follows:

<properties>
        <springframework.version>5.0.3.RELEASE</springframework.version>
        <jackson.version>2.9.4</jackson.version>
    </properties>

artifactId : spring-webmvc, jackson-databind, javax.servlet-api, jackson-module-jaxb-annotations, jackson-module-parameter-names, jackson-datatype-jdk8, jackson-datatype-jsr310

The exception reads as :

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('¬' (code 172)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: (byte[])"?? p"; line: 1, column: 2]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:663)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:561)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2624)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:826)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:723)
        at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4129)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3988)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3079)
        at com.wf.hrca.util.Convertor.unMarshal(Convertor.java:66)

Kindly suggest to fix this issue. I have tried googling but in vain. I assume its something to do with the JSON but standalone parsing is working fine.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Raghuveer
  • 2,859
  • 7
  • 34
  • 66
  • Seems that Jackson complains for some bad characters. My best guess is that the file may contain some special chars that are breaking the serialization process. Is there any chance you could post the POJO class to test this? – akortex Mar 03 '18 at 08:38
  • I can put it but its huge. They are simple POJO classes and `implements Serializable` – Raghuveer Mar 03 '18 at 09:38
  • https://stackoverflow.com/questions/41799519/how-to-parse-json-string-containing-special-characters – Shafin Mahmud Jul 23 '18 at 11:09

0 Answers0