diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java index a84e027a1..6a264c669 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java @@ -23,6 +23,7 @@ import com.linkedin.restli.server.annotations.PagingContextParam; import com.linkedin.restli.server.annotations.QueryParam; import com.linkedin.restli.server.annotations.RestMethod; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -210,7 +211,7 @@ public CollectionResult getSearchQueryCollectionRes .map(d -> (URN) ModelUtils.getUrnFromDocument(d)) .collect(Collectors.toList()); } else if (searchResult.getSearchResultMetadata().hasUrns()) { - matchedUrns = searchResult.getSearchResultMetadata().getUrns().stream().map(urn -> (URN) urn).collect(Collectors.toList()); + matchedUrns = searchResult.getSearchResultMetadata().getUrns().stream().map(this::toEntitySpecificUrn).collect(Collectors.toList()); } final Map urnValueMap = @@ -223,4 +224,12 @@ public CollectionResult getSearchQueryCollectionRes searchResult.getSearchResultMetadata().setUrns(new UrnArray(existingUrns.stream().map(urn -> (Urn) urn).collect(Collectors.toList()))) ); } + + private URN toEntitySpecificUrn(Urn urn) { + try { + return (URN) (_urnClass.getMethod("createFromUrn", Urn.class).invoke(null, urn)); + } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { + throw new RuntimeException(e); + } + } }