Skip to content

Commit

Permalink
Include null values into JSON produced by the REST API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Apr 26, 2021
1 parent 2814b34 commit 4042ecc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/cz/cvut/kbss/termit/config/WebAppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import cz.cvut.kbss.jopa.model.MultilingualString;
import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
import cz.cvut.kbss.jsonld.JsonLd;
import cz.cvut.kbss.jsonld.jackson.JsonLdModule;
import cz.cvut.kbss.termit.rest.servlet.DiagnosticsContextFilter;
import cz.cvut.kbss.termit.util.AdjustedUriTemplateProxyServlet;
import cz.cvut.kbss.termit.util.ConfigParam;
import cz.cvut.kbss.termit.util.Constants;
import cz.cvut.kbss.termit.util.json.ManageableIgnoreMixin;
import cz.cvut.kbss.termit.util.json.MultilingualStringDeserializer;
import cz.cvut.kbss.termit.util.json.MultilingualStringSerializer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
Expand Down Expand Up @@ -79,12 +81,14 @@ public ObjectMapper objectMapper() {
*/
public static ObjectMapper createJsonObjectMapper() {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
final SimpleModule multilingualStringModule = new SimpleModule();
multilingualStringModule.addSerializer(MultilingualString.class, new MultilingualStringSerializer());
multilingualStringModule.addDeserializer(MultilingualString.class, new MultilingualStringDeserializer());
objectMapper.registerModule(multilingualStringModule);
// Ignore UoW references injected into entities
objectMapper.addMixIn(UnitOfWorkImpl.class, ManageableIgnoreMixin.class);
// JSR 310 (Java 8 DateTime API)
objectMapper.registerModule(new JavaTimeModule());
return objectMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cz.cvut.kbss.termit.util.json;

import com.fasterxml.jackson.annotation.JsonIgnoreType;

/**
* Mixin declared to allow ignoring JOPA's Manageable reference to the current UnitOfWork
*/
@JsonIgnoreType
public class ManageableIgnoreMixin {
}

0 comments on commit 4042ecc

Please sign in to comment.