Use DefaultConversionService

This commit changes DefaultObjectDirectoryMapper to use
DefaultConversionService, preserving standard converters
that were there previous to deprecating ConverterManager.

Closes gh-1101
This commit is contained in:
Josh Cummings
2025-06-16 14:37:20 -06:00
parent d1a7944579
commit a2bc78bcf5
3 changed files with 30 additions and 4 deletions

View File

@@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.LdapDataEntry;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.ldap.convert.ConverterUtils;
import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
@@ -78,7 +78,7 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
}
private static ConverterManager createDefaultConverterManager() {
GenericConversionService conversionService = new GenericConversionService();
DefaultConversionService conversionService = new DefaultConversionService();
ConverterUtils.addDefaultConverters(conversionService);
return new ConversionServiceConverterManager(conversionService);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2023 the original author or authors.
* Copyright 2005-2025 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.
@@ -143,6 +143,20 @@ public class DefaultObjectDirectoryMapperTests {
verify(conversionService).convert(any(), any(Class.class));
}
// gh-1101
@Test
public void managerWhenEntityMapsLongThenConverts() {
this.tested.manageClass(UnitTestPersonWithIndexedDnAttributes.class);
UnitTestPersonWithIndexedDnAttributes testPerson = new UnitTestPersonWithIndexedDnAttributes();
testPerson.setFullName("Some Person");
testPerson.setAge(34L);
DirContextAdapter adapter = new DirContextAdapter("cn=Some Person, ou=Some Company, c=Sweden");
this.tested.mapToLdapDataEntry(testPerson, adapter);
assertThat(adapter.getStringAttribute("age")).isEqualTo("34");
testPerson = this.tested.mapFromLdapDataEntry(adapter, UnitTestPersonWithIndexedDnAttributes.class);
assertThat(testPerson.getAge()).isEqualTo(34L);
}
private void assertField(DefaultObjectDirectoryMapper.EntityData entityData, String fieldName,
String expectedAttributeName, String expectedDnAttributeName, boolean expectedBinary,
boolean expectedTransient, boolean expectedList, boolean expectedReadOnly) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2025 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.
@@ -18,6 +18,7 @@ package org.springframework.ldap.odm.core.impl;
import javax.naming.Name;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.DnAttribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
@@ -40,6 +41,9 @@ public class UnitTestPersonWithIndexedDnAttributes {
@DnAttribute(value = "c", index = 0)
private String country;
@Attribute(name = "age")
private Long age;
public void setFullName(String fullName) {
this.fullName = fullName;
}
@@ -52,4 +56,12 @@ public class UnitTestPersonWithIndexedDnAttributes {
this.country = country;
}
public Long getAge() {
return this.age;
}
public void setAge(Long age) {
this.age = age;
}
}