Skip to content

Commit

Permalink
JdbcCustomConversion does not reject non-Date related default convert…
Browse files Browse the repository at this point in the history
…ers.

Previously, JdbcCustomConversion rejected any default converter that was not converting from and to java.util.Date. This probably stemmed from the fact that up until recently, Spring Data Commons' CustomConversions only registered date related default converters. As of spring-projects/spring-data-commons#2315 we also support jMolecules' Association and Identifier converters. We've relaxed the rejection to only explicitly reject all non Date/Time related converters if the conversion is from/to java.util.Date but allow everything else out of the box.
  • Loading branch information
odrotbohm committed Mar 11, 2021
1 parent 0058752 commit 5175c6a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
6 changes: 6 additions & 0 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmolecules.integrations</groupId>
<artifactId>jmolecules-spring</artifactId>
<version>${jmolecules-integration}</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public JdbcCustomConversions(ConverterConfiguration converterConfiguration) {

private static boolean isDateTimeApiConversion(ConvertiblePair cp) {

if (cp.getSourceType().equals(java.util.Date.class) && cp.getTargetType().getTypeName().startsWith("java.time.")) {
return true;
if (cp.getSourceType().equals(java.util.Date.class)) {
return cp.getTargetType().getTypeName().startsWith("java.time.");
}

if (cp.getTargetType().equals(java.util.Date.class) && cp.getSourceType().getTypeName().startsWith("java.time.")) {
return true;
if (cp.getTargetType().equals(java.util.Date.class)) {
return cp.getSourceType().getTypeName().startsWith("java.time.");
}

return false;
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2021 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
*
* https://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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core.convert;

import static org.assertj.core.api.Assertions.*;

import org.jmolecules.ddd.types.Association;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link JdbcCustomConversions}.
*
* @author Oliver Drotbohm
*/
class JdbcCustomConversionsUnitTests {

@Test // #937
void registersNonDateDefaultConverter() {

JdbcCustomConversions conversions = new JdbcCustomConversions();

assertThat(conversions.hasCustomWriteTarget(Association.class)).isTrue();
assertThat(conversions.getSimpleTypeHolder().isSimpleType(Association.class));
}
}

0 comments on commit 5175c6a

Please # to comment.