From f9eb5b7a06d2e1623f09d7f3fbc3bfdfcf0912a2 Mon Sep 17 00:00:00 2001 From: David Bennett Date: Wed, 5 Jun 2024 16:56:01 -0500 Subject: [PATCH 1/2] Ignore Map.Entry in RosettaRowMapperFactory It is currently intercepting cases where we want to use the built-in [MapEntryMapper](https://jdbi.org/#mapentry-mapping). --- .../hubspot/rosetta/jdbi3/RosettaRowMapperFactory.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/RosettaJdbi3/src/main/java/com/hubspot/rosetta/jdbi3/RosettaRowMapperFactory.java b/RosettaJdbi3/src/main/java/com/hubspot/rosetta/jdbi3/RosettaRowMapperFactory.java index 0402102..ccfe8a6 100644 --- a/RosettaJdbi3/src/main/java/com/hubspot/rosetta/jdbi3/RosettaRowMapperFactory.java +++ b/RosettaJdbi3/src/main/java/com/hubspot/rosetta/jdbi3/RosettaRowMapperFactory.java @@ -4,6 +4,7 @@ import com.hubspot.rosetta.RosettaMapper; import com.hubspot.rosetta.util.SqlTableNameExtractor; import java.lang.reflect.Type; +import java.util.Map; import java.util.Optional; import org.jdbi.v3.core.config.ConfigRegistry; import org.jdbi.v3.core.generic.GenericTypes; @@ -35,7 +36,12 @@ public Optional> build(Type type, ConfigRegistry config) { private static boolean accepts(Type type, ConfigRegistry config) { Class rawType = GenericTypes.getErasedType(type); - if (rawType.isPrimitive() || rawType.isArray() || rawType.isAnnotation()) { + if ( + rawType.isPrimitive() || + rawType.isArray() || + rawType.isAnnotation() || + rawType.equals(Map.Entry.class) + ) { return false; } else if (rawType == Optional.class) { Optional optionalType = GenericTypes.findGenericParameter( From ef531265686d5ee9d13a04ed6949008a2a46facf Mon Sep 17 00:00:00 2001 From: David Bennett Date: Wed, 5 Jun 2024 17:07:38 -0500 Subject: [PATCH 2/2] Add a regression test --- .../hubspot/rosetta/jdbi3/RosettaRowMapperFactoryTest.java | 4 ++++ .../src/test/java/com/hubspot/rosetta/jdbi3/TestDao.java | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/RosettaRowMapperFactoryTest.java b/RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/RosettaRowMapperFactoryTest.java index 51e564e..38f70be 100644 --- a/RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/RosettaRowMapperFactoryTest.java +++ b/RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/RosettaRowMapperFactoryTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import java.util.Map; import org.junit.Test; public class RosettaRowMapperFactoryTest extends AbstractJdbiTest { @@ -21,5 +22,8 @@ public void itMapsObject() { TestObject actual = results.get(0); assertThat(actual).isEqualTo(expected); + + Map map = getDao().getAllMap(); + assertThat(map).containsOnly(Map.entry(1, expected)); } } diff --git a/RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/TestDao.java b/RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/TestDao.java index 8a9505b..380fde9 100644 --- a/RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/TestDao.java +++ b/RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/TestDao.java @@ -1,7 +1,9 @@ package com.hubspot.rosetta.jdbi3; import java.util.List; +import java.util.Map; import org.jdbi.v3.sqlobject.SqlObject; +import org.jdbi.v3.sqlobject.config.KeyColumn; import org.jdbi.v3.sqlobject.config.RegisterRowMapperFactory; import org.jdbi.v3.sqlobject.customizer.BindList.EmptyHandling; import org.jdbi.v3.sqlobject.statement.SqlQuery; @@ -12,6 +14,10 @@ public interface TestDao extends SqlObject { @SqlQuery("SELECT * FROM test_table") List getAll(); + @SqlQuery("SELECT * FROM test_table") + @KeyColumn("id") + Map getAllMap(); + @SqlQuery("SELECT * FROM test_list_table") List getAllList();