diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java index 40354e1ec..af11de4e4 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java @@ -1,11 +1,11 @@ /* - * Copyright (c) 2011 by the original author(s). + * Copyright 2011-2013 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -31,6 +31,7 @@ import org.springframework.core.convert.converter.ConverterFactory; import org.springframework.core.convert.converter.GenericConverter; import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; import org.springframework.core.convert.support.GenericConversionService; +import org.springframework.data.convert.JodaTimeConverters; import org.springframework.data.convert.ReadingConverter; import org.springframework.data.convert.WritingConverter; import org.springframework.data.mapping.model.SimpleTypeHolder; @@ -93,6 +94,7 @@ public class CustomConversions { this.converters.add(StringToBigIntegerConverter.INSTANCE); this.converters.add(URLToStringConverter.INSTANCE); this.converters.add(StringToURLConverter.INSTANCE); + this.converters.addAll(JodaTimeConverters.getConvertersToRegister()); this.converters.addAll(converters); for (Object c : this.converters) { diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java index c357c5605..65be46cf9 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 the original author or authors. + * Copyright 2011-2013 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. @@ -112,15 +112,7 @@ public class MappingMongoConverterUnitTests { @Test public void convertsJodaTimeTypesCorrectly() { - List> converters = new ArrayList>(); - converters.add(new LocalDateToDateConverter()); - converters.add(new DateToLocalDateConverter()); - - CustomConversions conversions = new CustomConversions(converters); - mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder()); - converter = new MappingMongoConverter(factory, mappingContext); - converter.setCustomConversions(conversions); converter.afterPropertiesSet(); Person person = new Person(); @@ -138,15 +130,7 @@ public class MappingMongoConverterUnitTests { @Test public void convertsCustomTypeOnConvertToMongoType() { - List> converters = new ArrayList>(); - converters.add(new LocalDateToDateConverter()); - converters.add(new DateToLocalDateConverter()); - - CustomConversions conversions = new CustomConversions(converters); - mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder()); - converter = new MappingMongoConverter(factory, mappingContext); - converter.setCustomConversions(conversions); converter.afterPropertiesSet(); LocalDate date = new LocalDate();