Skip to content

AsyncFeign doesn't work with type parameters on the base api interface. #1612

@voron86

Description

@voron86

I tried to use next interface with AsyncFeign:

@Headers({ "Content-Type: application/json", "Accept: application/json" })
public interface V1AsyncEndpoint<T> {

  @RequestLine("POST /api/v1/projects/{project}/{resource}/byids")
  @Headers("Authorization: Bearer {token}")
  CompletableFuture<T> getPageByIds(
      @Param("token") String token,
      @Param("project") String project,
      @Param("resource") String resource,
      @Param("items") Collection<Long> ids,
      @Param("ignoreUnknownIds") boolean ignoreUnknownIds,
      @Nullable
      @Param("aggregatedProperties") Collection<String> aggregatedProperties);
}

for Type:

class Data {
String a;
Long b;
}

But getPageByIds always returns com.google.gson.internal.LinkedTreeMap and then I get java.util.concurrent.CompletionException: java.lang.ClassCastException: class com.google.gson.internal.LinkedTreeMap

If I use

@Headers({ "Content-Type: application/json", "Accept: application/json" })
public interface V1AsyncEndpoint {

  @RequestLine("POST /api/v1/projects/{project}/{resource}/byids")
  @Headers("Authorization: Bearer {token}")
  CompletableFuture<Data> getPageByIds(
      @Param("token") String token,
      @Param("project") String project,
      @Param("resource") String resource,
      @Param("items") Collection<Long> ids,
      @Param("ignoreUnknownIds") boolean ignoreUnknownIds,
      @Nullable
      @Param("aggregatedProperties") Collection<String> aggregatedProperties);
}

everything works correctly.

I've made short debugging and I noticed the AsyncFeign decoder gets T as type instead of Data when deserialisation happens.

I use version: 11.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions