Adds json deserialization ignore for missing properties
This commit is contained in:
parent
67e0dbcb7c
commit
5f6224210b
|
@ -1,8 +1,10 @@
|
||||||
package eu.eudat.configurations;
|
package eu.eudat.configurations;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.Module;
|
import com.fasterxml.jackson.databind.Module;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
import eu.eudat.criteria.entities.Criteria;
|
import eu.eudat.criteria.entities.Criteria;
|
||||||
import eu.eudat.criteria.serialzier.CriteriaSerializer;
|
import eu.eudat.criteria.serialzier.CriteriaSerializer;
|
||||||
|
@ -22,6 +24,7 @@ public class JacksonConfiguration {
|
||||||
modules.add(criteriaSerializerModule);
|
modules.add(criteriaSerializerModule);
|
||||||
|
|
||||||
return new ObjectMapper()
|
return new ObjectMapper()
|
||||||
|
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
.registerModules(modules);
|
.registerModules(modules);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package eu.eudat.controllers.controllerhandler;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import eu.eudat.core.logger.Logger;
|
import eu.eudat.core.logger.Logger;
|
||||||
import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
|
import eu.eudat.core.models.exception.ApiExceptionLoggingModel;
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
|
@ -42,7 +43,7 @@ public class ControllerErrorHandler {
|
||||||
apiExceptionLoggingModel.setCode(HttpStatus.BAD_REQUEST);
|
apiExceptionLoggingModel.setCode(HttpStatus.BAD_REQUEST);
|
||||||
apiExceptionLoggingModel.setUser(principal);
|
apiExceptionLoggingModel.setUser(principal);
|
||||||
Map<String, String> exceptionMap = new HashMap<>();
|
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 {
|
try {
|
||||||
String json = ow.writeValueAsString(ex);
|
String json = ow.writeValueAsString(ex);
|
||||||
exceptionMap.put("exception", json);
|
exceptionMap.put("exception", json);
|
||||||
|
|
Loading…
Reference in New Issue