cancel
Showing results for 
Search instead for 
Did you mean: 
  • 1,154 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

 

Labels (2)
0 Kudos
2 Replies
lribas
Cadet
Cadet
  • 1,145 Views

Re: JAX-RS - JSON Attributes

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);

}

 

Tags (1)
Reply
Loading...
ramalho
Cadet
Cadet
  • 1,093 Views

Re: JAX-RS - JSON Attributes

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());
}

 

0 Kudos
Reply
Loading...
Join the discussion
You must log in to join this conversation.