Use Case
I have following rest client
@RegisterRestClient(configKey = "service")
public interface Service {
@POST
@Path("Invoice")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
Response request(@QueryParam("instance") String instance, @BeanParam Input input);
}
Input
is a class which is a POJO including properties like
public class Input {
@FormParam("title")
public String title;
@FormParam("description")
public String description;
Problem
The request to the API is working fine, but in my case, the order of properties does matter (The reason behind that is something, I cannot answer at the moment, sorry).
So sending title=Test&description=Testdescription
is different to description=Testdescription&title=Test
.
Other solutions I have tried
- With
Form
instead of POJO: No data is send to the server
@POST
@Path("Invoice")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
CustomResponse requestForm(@QueryParam("instance") String instance, @BeanParam Form form);
- With
Entit<Form>
: No data is send to the server
@POST
@Path("Invoice")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
CustomResponse requestForm(@QueryParam("instance") String instance, @BeanParam Entity<Form> form);
Assumption
I found out, that org.jboss.resteasy.client.jaxrs.internal.proxy.processors.FormProcessor
is using a HashMap
internally. I think that is exactly the problem, because there is no guaranteed order. Is my assumption correct?
Question
How can I work around that and always provide the same order for the API using the Microprofile Rest Client.
Workaround
It works with a org.jboss.resteasy.client.jaxrs.ResteasyClient
invoking like
Response response = target
.request(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_FORM_URLENCODED)
.post(Entity.form(form));