I use openFeign to attack the web by sending a Post request with a list of objects as parameters unfortunately the target web service does not understand the json format that I send because it expects a json with a slightly different format. see the code:

@FeignClient(name = "clientfeign",url = "http://192.168.x.x:8080")
public interface SRestClient {

    @PostMapping(path = "/api/method-adresse")
    List<TEbourse> checkFonctionnaire(@RequestBody List<TEbourse> demandes);
}

Objet:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TEbourse {
    private int id;
    private String nom;
    private String prenom;
    private String sexe;
    private String date_naissance;
    private String lieu_naissance;
    private String matricule;
    private String statut;
}

Format JSON envoyer:

[
      {
      
      "ID": "12",
      "date_naissance": "08/01/84",
      "lieu_naissance": "",
      "matricule": "",
      "nom": "XXXX",
      "prenom": "XXXX XX",
      "sexe": "M",
      "statut": ""
   },
      {
      
      "ID": "20",
      "date_naissance": "02/10/98",
      "lieu_naissance": "",
      "matricule": "",
       "nom": "XXXX",
      "prenom": "XXXX XX",
      "sexe": "M",
      "statut": ""
   },
      {
      
      "ID": "152",
      "date_naissance": "27/03/94",
      "lieu_naissance": "",
      "matricule": "",
       "nom": "XXXX",
      "prenom": "XXXX XX",
      "sexe": "M",
      "statut": ""
   }
]

On the other hand the web service deployed on webLogic expects a json format with a key in front and this doe when deploying on webLogic on wildly it is the same format sent by openFeigns:

{ "tEbourse":[
      {
      "date_naissance": "08/01/84",
      "ID": "12",
      "lieu_naissance": "",
      "matricule": "",
       "nom": "XXXX",
      "prenom": "XXXX XX",
      "sexe": "M",
      "statut": ""
   },
      {
      "date_naissance": "02/10/98",
      "ID": "20",
      "lieu_naissance": "",
      "matricule": "",
       "nom": "XXXX",
      "prenom": "XXXX XX",
      "sexe": "M",
      "statut": ""
   },
      {
      "date_naissance": "27/03/94",
      "ID": "152",
      "lieu_naissance": "",
      "matricule": "",
       "nom": "XXXX",
      "prenom": "XXXX XX",
      "sexe": "M",
      "statut": ""
   }
]} 

What do you think about the problem ?

how to send a request using similar JSON from Spring with OpenFeign.

Note: this problem only arises during deployment on webLogic but everything works for the case of wildfly

1

There are 1 best solutions below

1
On

If you need the same format as openFeigns you need a wrapper class for your TEbourse class.

It should be like below.

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TEbourseWrapper {
    private List<TEbourse> tEbourse;
}

In your SIPAERestClient do something like the below.

@FeignClient(name = "clientfeign",url = "http://192.168.x.x:8080")
public interface SIPAERestClient {

    @PostMapping(path = "/api/method-adresse")
    TEbourseWrapper checkFonctionnaire(@RequestBody TEbourseWrapper demandes);
}