I have a ResponseEntity<String> object to be serialized and un-serialized. I am having challenge in trying to de-serialize the data. Below are the code-snippet of the data.
private void marshalCompressedFileForResponseEntity(ResponseEntity<String> responseEntity, Path filenamePath) throws IOException {
try (OutputStream fileOutput = azureFs.create(filenamePath);
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutput)) {
mapper.writerFor(ResponseEntity.class).writeValue(gzipOutputStream,responseEntity);
//Mostly Incorrect - since type reference is at ResponseEntity.class
}
} finally {
cleanup(filenamePath);
}
}
Now the question is how do I de-serialize them. I tried the below sample code - but the editor throws obvious error.
public ResponseEntity<String> unMarshalLogForResponseEntity(Path path) throws IOException {
try (InputStream logFileInput = azureFs.open(path); GZIPInputStream gzipInputStream = new GZIPInputStream(logFileInput)) {
return mapper.readValue(gzipInputStream,ResponseEntity.class);
// You cannot provide ResponseEntity<String>.class
} catch (Exception e) {
logger.error("Error", e);
throw e;
}
}
Though note here that writerFor is again done at ResponseEntity.class and not for ResponseEntity<String>.class. I have tried multiple type - TypeReference etc. But none of them seems to work.