Skip to content

Commit e3aadd6

Browse files
ryantenneyodrotbohm
authored andcommitted
DATAMONGO-928 - Removed explicit default value for abbreviate-field-names from namespace XSD.
The default for boolean attributes leaks into the evaluation of XML namespace attributes which causes us being unable to detect whether two attributes have been set in a conflicting way. Fix the documentation on the field-naming-strategy-ref attribute. Original pull request: spring-projects#183. Related pull request: spring-projects#177. Related ticket: DATAMONGO-925.
1 parent aa06d52 commit e3aadd6

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.5.xsd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ The base package in which to scan for entities annotated with @Document
212212
<xsd:union memberTypes="xsd:boolean xsd:string"/>
213213
</xsd:simpleType>
214214
</xsd:attribute>
215-
<xsd:attribute name="abbreviate-field-names" use="optional" default="false">
215+
<xsd:attribute name="abbreviate-field-names" use="optional">
216216
<xsd:annotation>
217217
<xsd:documentation source="org.springframework.data.mongodb.core.mapping.CamelCaseAbbreviatingFieldNamingStrategy">
218218
Enables abbreviating the field names for domain class properties to the
219-
first character of their camel case names, e.g. fooBar -> fb.
219+
first character of their camel case names, e.g. fooBar -> fb. Defaults to false.
220220
</xsd:documentation>
221221
</xsd:annotation>
222222
<xsd:simpleType>
@@ -226,7 +226,7 @@ The base package in which to scan for entities annotated with @Document
226226
<xsd:attribute name="field-naming-strategy-ref" type="fieldNamingStrategyRef" use="optional">
227227
<xsd:annotation>
228228
<xsd:documentation source="org.springframework.data.mongodb.core.mapping.FieldNamingStrategy">
229-
The reference to a MappingContext. Will default to 'mappingContext'.
229+
The reference to a FieldNamingStrategy.
230230
</xsd:documentation>
231231
</xsd:annotation>
232232
</xsd:attribute>
@@ -654,4 +654,4 @@ The GridFs bucket string.]]></xsd:documentation>
654654
</xsd:attribute>
655655
</xsd:complexType>
656656
</xsd:element>
657-
</xsd:schema>
657+
</xsd:schema>

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/MappingMongoConverterParserIntegrationTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.Test;
2626
import org.junit.rules.ExpectedException;
2727
import org.springframework.beans.factory.config.BeanDefinition;
28+
import org.springframework.beans.factory.config.BeanReference;
2829
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
2930
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
3031
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -49,6 +50,7 @@
4950
* @author Oliver Gierke
5051
* @author Thomas Darimont
5152
* @author Christoph Strobl
53+
* @author Ryan Tenney
5254
*/
5355
public class MappingMongoConverterParserIntegrationTests {
5456

@@ -134,6 +136,25 @@ public void shouldThrowBeanDefinitionParsingExceptionIfConverterDefinedAsNestedB
134136
loadNestedBeanConfiguration();
135137
}
136138

139+
/**
140+
* @see DATAMONGO-925, DATAMONGO-928
141+
*/
142+
@Test
143+
public void shouldSupportCustomFieldNamingStrategy() {
144+
145+
BeanDefinitionRegistry factory = new DefaultListableBeanFactory();
146+
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
147+
reader.loadBeanDefinitions(new ClassPathResource("namespace/converter-custom-fieldnamingstrategy.xml"));
148+
149+
BeanDefinition definition = reader.getRegistry().getBeanDefinition(
150+
"mappingConverterWithCustomFieldNamingStrategy.mongoMappingContext");
151+
152+
BeanReference value = (BeanReference) definition.getPropertyValues().getPropertyValue("fieldNamingStrategy")
153+
.getValue();
154+
155+
assertThat(value.getBeanName(), is("customFieldNamingStrategy"));
156+
}
157+
137158
private void loadValidConfiguration() {
138159
this.loadConfiguration("namespace/converter.xml");
139160
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
5+
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
6+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
7+
8+
<mongo:mapping-converter id="mappingConverterWithCustomFieldNamingStrategy" field-naming-strategy-ref="customFieldNamingStrategy" />
9+
10+
<bean id="customFieldNamingStrategy" class="org.mockito.Mockito" factory-method="mock">
11+
<property name="type" value="org.springframework.data.mongodb.core.mapping.FieldNamingStrategy" />
12+
</bean>
13+
</beans>

0 commit comments

Comments
 (0)