-1

i am new to web services, i want to pass JSON object as input parameter to POST method and return JSON object from that method.

Input-

{
     "RecognizeInput":
     {
         "SignatureString":""
     }
}

Output-

{
    "RecognizeOutput": {
        "Status": "",
        "Message": "",
        "NumMatches": "2",
        "IvMatchedProducts": {
            "IvMatchedProduct": [
                {
                    "Name": "prod1",
                    "Description": "prodDecs",
                    "ThumbnailImg": "",
                    "URL": "",
                    "Rating": "",
                    "Price": ""
                },
                {
                    "Name": "prod2",
                    "Description": "prodDecs",
                    "ThumbnailImg": "",
                    "URL": "",
                    "Rating": "",
                    "Price": ""
                }
            ]
        }
    }
Tushar
  • 3,527
  • 9
  • 27
  • 49
ABG
  • 1
  • 3

1 Answers1

-1

You can do this with a help of bean class. Create a Rest service which can produces and consumes media type as application/json with HTTP method POST to do the trick.

Bean class

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="Student")
public class Student {

String id;
String name;
public String getId() {
    return id;
}
public void setId(String id) {
    this.id = id;
}

public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
}

REST Root class

@Path("s")
public class StudentService {

@POST
@Consumes({ MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON })
public Response post(Student s){
        String accept = MediaType.APPLICATION_JSON;
    return Response.ok(s, accept).build();
}
}

Your Request can be

{"id":"111","name":"H11H"}

And the Response

{"id":"111","name":"H11H"}
Pasupathi Rajamanickam
  • 1,982
  • 1
  • 24
  • 48