Add PropertyNamingStrategy field to ObjectMapperFB
Issue: SPR-11431
This commit is contained in:
parent
1dedb67fbc
commit
268657b6cb
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -34,6 +34,7 @@ import com.fasterxml.jackson.databind.JsonSerializer;
|
|||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
|
||||
|
|
@ -143,6 +144,8 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
|||
|
||||
private boolean findModulesViaServiceLoader;
|
||||
|
||||
private PropertyNamingStrategy propertyNamingStrategy;
|
||||
|
||||
private ClassLoader beanClassLoader;
|
||||
|
||||
|
||||
|
|
@ -328,6 +331,15 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
|||
this.findModulesViaServiceLoader = findModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a {@link com.fasterxml.jackson.databind.PropertyNamingStrategy} to
|
||||
* configure the {@link ObjectMapper} with.
|
||||
* @@since 4.0.2
|
||||
*/
|
||||
public void setPropertyNamingStrategy(PropertyNamingStrategy propertyNamingStrategy) {
|
||||
this.propertyNamingStrategy = propertyNamingStrategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader beanClassLoader) {
|
||||
this.beanClassLoader = beanClassLoader;
|
||||
|
|
@ -385,6 +397,10 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
|||
registerWellKnownModulesIfAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.propertyNamingStrategy != null) {
|
||||
this.objectMapper.setPropertyNamingStrategy(this.propertyNamingStrategy);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -32,6 +32,7 @@ import com.fasterxml.jackson.databind.JsonSerializer;
|
|||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.cfg.DeserializerFactoryConfig;
|
||||
import com.fasterxml.jackson.databind.cfg.SerializerFactoryConfig;
|
||||
|
|
@ -49,7 +50,12 @@ import org.junit.Test;
|
|||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
/**
|
||||
* Test cases for {@link Jackson2ObjectMapperFactoryBean} class.
|
||||
|
|
@ -186,6 +192,16 @@ public class Jackson2ObjectMapperFactoryBeanTests {
|
|||
return ((BasicDeserializerFactory) objectMapper.getDeserializationContext().getFactory()).getFactoryConfig();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyNamingStrategy() {
|
||||
PropertyNamingStrategy strategy = new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy();
|
||||
this.factory.setPropertyNamingStrategy(strategy);
|
||||
this.factory.afterPropertiesSet();
|
||||
|
||||
assertSame(strategy, this.factory.getObject().getSerializationConfig().getPropertyNamingStrategy());
|
||||
assertSame(strategy, this.factory.getObject().getDeserializationConfig().getPropertyNamingStrategy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompleteSetup() {
|
||||
NopAnnotationIntrospector annotationIntrospector = NopAnnotationIntrospector.instance;
|
||||
|
|
|
|||
Loading…
Reference in New Issue