Skip to content

Commit

Permalink
Merge pull request #103 from HubSpot/ignore-map-entry
Browse files Browse the repository at this point in the history
Ignore Map.Entry in RosettaRowMapperFactory
  • Loading branch information
jaredstehler authored Jun 6, 2024
2 parents 6818b7f + ef53126 commit ea87dae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,7 +36,12 @@ public Optional<RowMapper<?>> 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<Type> optionalType = GenericTypes.findGenericParameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,5 +22,8 @@ public void itMapsObject() {

TestObject actual = results.get(0);
assertThat(actual).isEqualTo(expected);

Map<Integer, TestObject> map = getDao().getAllMap();
assertThat(map).containsOnly(Map.entry(1, expected));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +14,10 @@ public interface TestDao extends SqlObject {
@SqlQuery("SELECT * FROM test_table")
List<TestObject> getAll();

@SqlQuery("SELECT * FROM test_table")
@KeyColumn("id")
Map<Integer, TestObject> getAllMap();

@SqlQuery("SELECT * FROM test_list_table")
List<TestListObject> getAllList();

Expand Down

0 comments on commit ea87dae

Please sign in to comment.