HI, folks
Is it possible to create a POST web service by getting each JSON attribute in an attribute of the method? (Without creating a POJO class representing this JSON)
For example, I want to send the JSON bellow.
{
    "name":"Smith",
    "email":"smith@smiths.com"
}and the web service implementation is :
@POST
@Produces(MediaType.APPLICATION_JSON)
public void register(String name, String email) {...}
Tks
Hello RogerioLSanto.
This form I believe that is not possible, but you can do different, by example:
{
    "name":"Smith",
    "email":"smith@smiths.com"
}
@POST
@Produces(MediaType.APPLICATION_JSON)
public void register(String body) {
  
  JSONParser parser = new JSONParser();
  JSONObject json = (JSONObject) parser.parse(body);
}
You need to wrap it.
e.g:
public class Person {
    private String name; 
    private String email; 
    // gets and sets
}
@@POST
@Produces(MediaType.APPLICATION_JSON)
public void register(Person person) 
  
  System.out.println(person.getName());
  System.out.println(person.getEmail());
}
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.