OpenFeign/feign

incomplete Object information when serialize object with Gson

Open

#2 485 ouverte le 24 juil. 2024

Voir sur GitHub
 (3 commentaires) (0 réactions) (0 assignés)Java (1 911 forks)batch import
bughelp wanted

Métriques du dépôt

Stars
 (9 070 stars)
Métriques de merge PR
 (Merge moyen 2j 17h) (71 PRs mergées en 30 j)

Description


    @PostMapping("/message/send?access_token={access_token}")
    MessageResponseDTO send(@RequestParam("access_token") String accessToken, @RequestBody AbsMessage message);

Such as the code, I need to call it,the interface has different performance depends on the Object passed. However AbsMessage is a abstract class,when I call it need to pass an object which instance of AbsMessage. But the reuest body doesn't conatin any field from the runtime sub class whic I passed. All fields are from the abstract class. I find the cause at last.

  GsonEncoder#encode(Object object, Type bodyType, RequestTemplate template)
  @Override
  public void encode(Object object, Type bodyType, RequestTemplate template) {
    template.body(gson.toJson(object, bodyType));
  }

It serializes object with the type which declared in the function,not runtime type of the passed object. If gson.toJson(object),It appears normal.

Guide contributeur