Skip to content

Commit a2bc78b

Browse files
committed
Use DefaultConversionService
This commit changes DefaultObjectDirectoryMapper to use DefaultConversionService, preserving standard converters that were there previous to deprecating ConverterManager. Closes gh-1101
1 parent d1a7944 commit a2bc78b

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
import org.springframework.LdapDataEntry;
4141
import org.springframework.core.convert.ConversionService;
42-
import org.springframework.core.convert.support.GenericConversionService;
42+
import org.springframework.core.convert.support.DefaultConversionService;
4343
import org.springframework.ldap.convert.ConverterUtils;
4444
import org.springframework.ldap.filter.AndFilter;
4545
import org.springframework.ldap.filter.EqualsFilter;
@@ -78,7 +78,7 @@ public DefaultObjectDirectoryMapper() {
7878
}
7979

8080
private static ConverterManager createDefaultConverterManager() {
81-
GenericConversionService conversionService = new GenericConversionService();
81+
DefaultConversionService conversionService = new DefaultConversionService();
8282
ConverterUtils.addDefaultConverters(conversionService);
8383
return new ConversionServiceConverterManager(conversionService);
8484
}

core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2023 the original author or authors.
2+
* Copyright 2005-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -143,6 +143,20 @@ public void mapToLdapDataEntryWhenCustomConversionServiceThenUses() {
143143
verify(conversionService).convert(any(), any(Class.class));
144144
}
145145

146+
// gh-1101
147+
@Test
148+
public void managerWhenEntityMapsLongThenConverts() {
149+
this.tested.manageClass(UnitTestPersonWithIndexedDnAttributes.class);
150+
UnitTestPersonWithIndexedDnAttributes testPerson = new UnitTestPersonWithIndexedDnAttributes();
151+
testPerson.setFullName("Some Person");
152+
testPerson.setAge(34L);
153+
DirContextAdapter adapter = new DirContextAdapter("cn=Some Person, ou=Some Company, c=Sweden");
154+
this.tested.mapToLdapDataEntry(testPerson, adapter);
155+
assertThat(adapter.getStringAttribute("age")).isEqualTo("34");
156+
testPerson = this.tested.mapFromLdapDataEntry(adapter, UnitTestPersonWithIndexedDnAttributes.class);
157+
assertThat(testPerson.getAge()).isEqualTo(34L);
158+
}
159+
146160
private void assertField(DefaultObjectDirectoryMapper.EntityData entityData, String fieldName,
147161
String expectedAttributeName, String expectedDnAttributeName, boolean expectedBinary,
148162
boolean expectedTransient, boolean expectedList, boolean expectedReadOnly) {

core/src/test/java/org/springframework/ldap/odm/core/impl/UnitTestPersonWithIndexedDnAttributes.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2013 the original author or authors.
2+
* Copyright 2005-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import javax.naming.Name;
2020

21+
import org.springframework.ldap.odm.annotations.Attribute;
2122
import org.springframework.ldap.odm.annotations.DnAttribute;
2223
import org.springframework.ldap.odm.annotations.Entry;
2324
import org.springframework.ldap.odm.annotations.Id;
@@ -40,6 +41,9 @@ public class UnitTestPersonWithIndexedDnAttributes {
4041
@DnAttribute(value = "c", index = 0)
4142
private String country;
4243

44+
@Attribute(name = "age")
45+
private Long age;
46+
4347
public void setFullName(String fullName) {
4448
this.fullName = fullName;
4549
}
@@ -52,4 +56,12 @@ public void setCountry(String country) {
5256
this.country = country;
5357
}
5458

59+
public Long getAge() {
60+
return this.age;
61+
}
62+
63+
public void setAge(Long age) {
64+
this.age = age;
65+
}
66+
5567
}

0 commit comments

Comments
 (0)