Skip to content
Snippets Groups Projects
Commit 8d058e0e authored by Rick Herrick's avatar Rick Herrick
Browse files

Added Hibernate 4 module to JSON serializer/deserializer to remove proxy...

Added Hibernate 4 module to JSON serializer/deserializer to remove proxy properties in serialized JSON.
parent a25bba40
No related branches found
No related tags found
No related merge requests found
...@@ -327,6 +327,7 @@ dependencies { ...@@ -327,6 +327,7 @@ dependencies {
compile "com.fasterxml.jackson.core:jackson-core:${vJackson}" compile "com.fasterxml.jackson.core:jackson-core:${vJackson}"
compile "com.fasterxml.jackson.core:jackson-databind:${vJackson}" compile "com.fasterxml.jackson.core:jackson-databind:${vJackson}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${vJackson}" compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${vJackson}"
compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate4:${vJackson}"
compile "org.json:json:20151123" compile "org.json:json:20151123"
compile "xerces:xercesImpl:2.11.0" compile "xerces:xercesImpl:2.11.0"
......
package org.nrg.xnat.configuration; package org.nrg.xnat.configuration;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
import org.nrg.framework.annotations.XapiRestController; import org.nrg.framework.annotations.XapiRestController;
import org.nrg.xnat.spawner.configuration.SpawnerConfig; import org.nrg.xnat.spawner.configuration.SpawnerConfig;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -35,9 +38,12 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -35,9 +38,12 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
public class WebConfig extends WebMvcConfigurerAdapter { public class WebConfig extends WebMvcConfigurerAdapter {
@Bean @Bean
public Jackson2ObjectMapperBuilder objectMapperBuilder() { public Jackson2ObjectMapperBuilder objectMapperBuilder() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); return new Jackson2ObjectMapperBuilder()
builder.serializationInclusion(JsonInclude.Include.NON_NULL); .serializationInclusion(JsonInclude.Include.NON_NULL)
return builder; .failOnEmptyBeans(false)
.featuresToEnable(JsonParser.Feature.ALLOW_SINGLE_QUOTES, JsonParser.Feature.ALLOW_YAML_COMMENTS)
.featuresToDisable(SerializationFeature.FAIL_ON_EMPTY_BEANS, SerializationFeature.WRITE_NULL_MAP_VALUES)
.modules(new Hibernate4Module());
} }
@Override @Override
......
...@@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; ...@@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
import org.nrg.framework.datacache.SerializerRegistry; import org.nrg.framework.datacache.SerializerRegistry;
import org.nrg.framework.exceptions.NrgServiceException; import org.nrg.framework.exceptions.NrgServiceException;
import org.nrg.framework.services.ContextService; import org.nrg.framework.services.ContextService;
...@@ -72,6 +73,7 @@ public class RootConfig { ...@@ -72,6 +73,7 @@ public class RootConfig {
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
mapper.registerModule(new Hibernate4Module());
return mapper; return mapper;
} }
...@@ -83,6 +85,7 @@ public class RootConfig { ...@@ -83,6 +85,7 @@ public class RootConfig {
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
mapper.registerModule(new Hibernate4Module());
return mapper; return mapper;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment