Adds json deserialization ignore for missing properties

This commit is contained in:
ikalyvas 2019-05-29 13:55:13 +03:00
parent 67e0dbcb7c
commit 5f6224210b
2 changed files with 5 additions and 1 deletions

View File

@ -1,8 +1,10 @@
package eu.eudat.configurations;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import eu.eudat.criteria.entities.Criteria;
import eu.eudat.criteria.serialzier.CriteriaSerializer;
@ -22,6 +24,7 @@ public class JacksonConfiguration {
modules.add(criteriaSerializerModule);
return new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModules(modules);
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.controllers.controllerhandler;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import eu.eudat.core.logger.Logger;
import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
import eu.eudat.models.data.helpers.responses.ResponseItem;
@ -42,7 +43,7 @@ public class ControllerErrorHandler {
apiExceptionLoggingModel.setCode(HttpStatus.BAD_REQUEST);
apiExceptionLoggingModel.setUser(principal);
Map<String, String> exceptionMap = new HashMap<>();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
ObjectWriter ow = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false).writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(ex);
exceptionMap.put("exception", json);