com.fasterxml.jackson.core.JsonParseException: Unexpected character ((CTRL-CHAR, code 137)): expected a valid value

1.1k Views Asked by At

I am using google drive rest api to fetch data from drive to my app. Whenever I tried to fetch the data into inputStream, got this error:

W/System.err:  com.fasterxml.jackson.core.JsonParseException: Unexpected character ((CTRL-CHAR, code 137)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
W/System.err:  at [Source: com.google.api.client.http.javanet.NetHttpResponse$SizeValidatingInputStream@2975e41; line: 1, column: 2]

my code snippet:

GoogleCredential googleAccessCredential = new GoogleCredential().setAccessToken(accessToken);
NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

Drive drive = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, googleAccessCredential)
                                    .setApplicationName("Test")
                                    .build();
inputStream = drive.files().get("fileId").executeMediaAsInputStream();

I searched a lot but didn't get any feasible solution. I tried to change the header but got same error

inputStream = drive.files().get("fileId").setRequestHeaders(new HttpHeaders().setAccept("image/png")).executeAsInputStream();

I also tried with "application/json" and "application/octet-stream" headers.

access token is given hard coded

0

There are 0 best solutions below