diff --git a/elide-core/src/main/java/com/yahoo/elide/core/EntityDictionary.java b/elide-core/src/main/java/com/yahoo/elide/core/EntityDictionary.java index 569796c07d..2732198a2a 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/EntityDictionary.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/EntityDictionary.java @@ -97,6 +97,7 @@ public class EntityDictionary { @Getter protected final Injector injector; + @Getter protected final Function serdeLookup ; public final static String REGULAR_ID_NAME = "id"; diff --git a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapStoreTransaction.java b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapStoreTransaction.java index 606525e280..cc3ccbcf73 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapStoreTransaction.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapStoreTransaction.java @@ -14,6 +14,7 @@ import com.yahoo.elide.request.EntityProjection; import com.yahoo.elide.request.Relationship; import com.yahoo.elide.request.Sorting; +import com.yahoo.elide.utils.coerce.converters.Serde; import java.io.IOException; import java.io.Serializable; @@ -149,13 +150,17 @@ public Iterable loadObjects(EntityProjection projection, @Override public Object loadObject(EntityProjection projection, Serializable id, RequestScope scope) { + EntityDictionary dictionary = scope.getDictionary(); + synchronized (dataStore) { Map data = dataStore.get(projection.getType()); if (data == null) { return null; } - Object obj = data.get(id.toString()); - return obj; + Serde serde = dictionary.getSerdeLookup().apply(id.getClass()); + + String idString = (serde == null) ? id.toString() : (String) serde.serialize(id); + return data.get(idString); } } diff --git a/elide-integration-tests/src/test/java/com/yahoo/elide/tests/EmbeddedIdIT.java b/elide-integration-tests/src/test/java/com/yahoo/elide/tests/EmbeddedIdIT.java index fafaceb8e0..f991a7508a 100644 --- a/elide-integration-tests/src/test/java/com/yahoo/elide/tests/EmbeddedIdIT.java +++ b/elide-integration-tests/src/test/java/com/yahoo/elide/tests/EmbeddedIdIT.java @@ -30,13 +30,14 @@ import com.yahoo.elide.core.EntityDictionary; import com.yahoo.elide.core.HttpStatus; import com.yahoo.elide.initialization.GraphQLIntegrationTest; +import com.yahoo.elide.utils.coerce.CoerceUtil; import com.google.common.collect.Sets; import example.embeddedid.Address; import example.embeddedid.AddressSerde; import example.embeddedid.Building; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import lombok.Data; @@ -45,7 +46,6 @@ import java.util.Arrays; import java.util.HashMap; -@Tag("skipInMemory") public class EmbeddedIdIT extends GraphQLIntegrationTest { protected Address address1 = new Address(0, "Bullion Blvd", 40121); @@ -53,6 +53,11 @@ public class EmbeddedIdIT extends GraphQLIntegrationTest { protected Address address3 = new Address(1800, "South First Street", 61820); protected AddressSerde serde = new AddressSerde(); + @BeforeAll + public void beforeAll() { + CoerceUtil.register(Address.class, serde); + } + @BeforeEach public void setup() throws IOException { dataStore.populateEntityDictionary(new EntityDictionary(new HashMap<>()));