title: How to pass multiple arguments in a JAX-RS method using JSON-B provider
body: <p>I have a service class exposed through JAX-RS using JSON-B as the provider for (de)serialization, all wired using CDI. The environment is a Jakarta/Java EE 8 (Java SE 8) server (e.g. Wildfly 22):</p>
  <pre><code>@RequestScoped
  public class PersonService {
  
     public Long addPerson(String name, Pet pet, Country bornCountry) {
        //Pet and Country are custom classes that may be annotated with JSON-B annotations.
     }
  }
  </code></pre>
  <pre><code>@RequestScoped
  @Consumes(APPLICATION_JSON)
  @Produces(APPLICATION_JSON)
  @Path(&quot;/PersonService&quot;)
  public class PersonServiceRS {
  
     @Inject
     private PersonService personService;
  
     @POST
     @Path(&quot;/addPerson&quot;)
     public Response addPerson(AddPersonParameters parameters) {
        return Response
           .ok(personService.addPerson(
              parameters.name,
              parameters.pet,
              parameters.bornCountry
           ))
           .build();
     }
  }
  </code></pre>
  <pre><code>public class AddPersonParameters {
  
     public String name;
     public Pet pet;
     public Country bornCountry;
  
     public AddPersonParameters() { this(null, null, null); }
  
     public AddPersonParameters(String name, Pet pet, Country bornCountry) {
        this.name = name;
        this.pet = pet;
        this.bornCountry = bornCountry;
     }
  }
  </code></pre>
  <p>Using the JAX-RS Client API, the call to the service is something like this:</p>
  <pre><code>response = client
     .target(&quot;...&quot;)
     .request(APPLICATION_JSON)
     .post(Entity.json(new AddPersonParameters(
        aName,
        aPet,
        aBornCountry
     )));
  </code></pre>
  <p>Because JAX-RS has no automatic (de)composing of multiple arguments, I have to declare the class <em>AddPersonParameters</em> just to be a wrapper of the arguments of the method and satisfy JSON-B automatic (de)serialization.</p>
  <p><strong>A: Is there any way to avoid the argument wrapper class <em>AddPersonParameters</em> definition?</strong></p>
  <p>Suppose a <em>JsonEntity</em> custom general class similar in usage to a <em>Map&lt;String, Object&gt;</em> that could be used like this:</p>
  <pre><code>//Service
  public Response addPerson(JsonEntity parameters) {
     return Response
        .ok(personService.addPerson(
           parameters.get(String.class, &quot;name&quot;),
           parameters.get(Pet.class, &quot;pet&quot;),
           parameters.get(Country.class, &quot;bornCountry&quot;)
        ))
        .build();
  }
  </code></pre>
  <pre><code>//Client
  response = client
     .target(&quot;...&quot;)
     .request(APPLICATION_JSON)
     .post(Entity.json(new JsonEntity() {
        {
           add(&quot;name&quot;, aName),
           add(&quot;pet&quot;, aPet),
           add(&quot;bornCountry&quot;, aBornCountry)
        }
     }));
  </code></pre>
  <p><strong>B: How could <em>JsonEntity</em> be implemented in such a way it fulfills JSON-B?</strong></p>
  <p><em>NOTE: I know REST practitioners would say this is too RPC stylish ;)</em></p>