RogerioLSantos

Mission Specialist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2019
08:54 PM
- 3,456 Views
JAX-RS - JSON Attributes
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
2 Replies
lribas

Cadet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2019
09:24 PM
- 3,447 Views
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);
}
ramalho

Cadet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2019
09:18 PM
- 3,395 Views
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());
}
Join the discussion
You must log in to join this conversation.