test Switched back to ObejctMapper

This commit is contained in:
deiflaender 2022-05-11 10:19:13 +02:00
parent cc2d02162d
commit fd2762e0f7

View File

@ -2,6 +2,7 @@ package com.iqser.red.service.redaction.v1.server.storage;
import com.dslplatform.json.DslJson; import com.dslplatform.json.DslJson;
import com.dslplatform.json.runtime.Settings; import com.dslplatform.json.runtime.Settings;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
import com.iqser.red.service.redaction.v1.model.ImportedRedactions; import com.iqser.red.service.redaction.v1.model.ImportedRedactions;
import com.iqser.red.service.redaction.v1.model.RedactionLog; import com.iqser.red.service.redaction.v1.model.RedactionLog;
@ -29,7 +30,7 @@ public class RedactionStorageService {
private final StorageService storageService; private final StorageService storageService;
private final DslJson<Object> dslJson = new DslJson<>(Settings.basicSetup()); private final ObjectMapper objectMapper;
@SneakyThrows @SneakyThrows
@ -41,10 +42,8 @@ public class RedactionStorageService {
@SneakyThrows @SneakyThrows
public void storeObject(String dossierId, String fileId, FileType fileType, Object any) { public void storeObject(String dossierId, String fileId, FileType fileType, Object any) {
var baos = new ByteArrayOutputStream(); var bytes = objectMapper.writeValueAsBytes(any);
dslJson.newWriter(); storageService.storeObject(StorageIdUtils.getStorageId(dossierId, fileId, fileType), bytes);
dslJson.serialize(any, baos);
storageService.storeObject(StorageIdUtils.getStorageId(dossierId, fileId, fileType), baos.toByteArray());
} }
@SneakyThrows @SneakyThrows
@ -65,8 +64,7 @@ public class RedactionStorageService {
} }
try { try {
dslJson.newReader(); return objectMapper.readValue(inputStreamResource.getInputStream(), ImportedRedactions.class);
return dslJson.deserialize(ImportedRedactions.class, inputStreamResource.getInputStream());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Could not imported redactions", e); throw new RuntimeException("Could not imported redactions", e);
} }
@ -84,8 +82,7 @@ public class RedactionStorageService {
} }
try { try {
dslJson.newReader(); return objectMapper.readValue(inputStreamResource.getInputStream(), RedactionLog.class);
return dslJson.deserialize(RedactionLog.class, inputStreamResource.getInputStream());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Could not convert RedactionLog", e); throw new RuntimeException("Could not convert RedactionLog", e);
} }
@ -103,8 +100,7 @@ public class RedactionStorageService {
} }
try { try {
dslJson.newReader(); return objectMapper.readValue(inputStreamResource.getInputStream(), Text.class);
return dslJson.deserialize(Text.class, inputStreamResource.getInputStream());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Could not convert Text", e); throw new RuntimeException("Could not convert Text", e);
} }
@ -121,8 +117,7 @@ public class RedactionStorageService {
} }
try { try {
dslJson.newReader(); return objectMapper.readValue(inputStreamResource.getInputStream(), NerEntities.class);
return dslJson.deserialize(NerEntities.class, inputStreamResource.getInputStream());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Could not convert NER Entities", e); throw new RuntimeException("Could not convert NER Entities", e);
} }
@ -133,8 +128,7 @@ public class RedactionStorageService {
try { try {
var sectionGrid = storageService.getObject(StorageIdUtils.getStorageId(dossierId, fileId, FileType.SECTION_GRID)); var sectionGrid = storageService.getObject(StorageIdUtils.getStorageId(dossierId, fileId, FileType.SECTION_GRID));
dslJson.newReader(); return objectMapper.readValue(sectionGrid.getInputStream(), SectionGrid.class);
return dslJson.deserialize(SectionGrid.class, sectionGrid.getInputStream());
} catch (StorageObjectDoesNotExist e) { } catch (StorageObjectDoesNotExist e) {
throw new NotFoundException("Section Grid is not available."); throw new NotFoundException("Section Grid is not available.");
} catch (IOException e) { } catch (IOException e) {