From a2bc78bcf5910d00fa6d216785d89fb9dcc801ef Mon Sep 17 00:00:00 2001 From: Josh Cummings <3627351+jzheaux@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:37:20 -0600 Subject: [PATCH] Use DefaultConversionService This commit changes DefaultObjectDirectoryMapper to use DefaultConversionService, preserving standard converters that were there previous to deprecating ConverterManager. Closes gh-1101 --- .../core/impl/DefaultObjectDirectoryMapper.java | 4 ++-- .../impl/DefaultObjectDirectoryMapperTests.java | 16 +++++++++++++++- .../UnitTestPersonWithIndexedDnAttributes.java | 14 +++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java b/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java index cd69fabc..b65bbd8e 100644 --- a/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java +++ b/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java @@ -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); } diff --git a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java index f2ea363b..595b48c2 100644 --- a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java +++ b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java @@ -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) { diff --git a/core/src/test/java/org/springframework/ldap/odm/core/impl/UnitTestPersonWithIndexedDnAttributes.java b/core/src/test/java/org/springframework/ldap/odm/core/impl/UnitTestPersonWithIndexedDnAttributes.java index 4e82f0b8..370bc0af 100644 --- a/core/src/test/java/org/springframework/ldap/odm/core/impl/UnitTestPersonWithIndexedDnAttributes.java +++ b/core/src/test/java/org/springframework/ldap/odm/core/impl/UnitTestPersonWithIndexedDnAttributes.java @@ -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; + } + }