How to send JSON object from POSTMAN to Restful webservices

I am trying to send JSON from POSTMAN to a RESTful web service. I followed this tutorial URL to send JSON through POSTMAN.

My URL:

HTTP: // local: 8080 / MyWebservice / rest / dataInsert / insert

My service method:

@POST
    @Path("/insert")
    @Consumes(MediaType.APPLICATION_JSON)
    public String insertData(JSONObject jsonlist) throws UnknownHostException;

My impl:

@Override
    public String insertData(JSONObject jsonlist) throws UnknownHostException {
        System.out.println(jsonlist);
        insertDataDao.insertData(jsonlist);
        return "SUCCESS";
    }

My DAO:

public  String insertData(JSONObject jsonlist) throws UnknownHostException{
        System.out.println(jsonlist);
        MongoConnection mongoconnection = new MongoConnection();
        MongoClient mongoclient = mongoconnection.getMongoClient();

        MongoDatabase db = mongoclient.getDatabase("mydb");
        MongoCollection<Document> col = db.getCollection("col");

        String jsonString = jsonlist.toString();
        System.out.println(jsonString);

        Document doc = Document.parse(jsonString);
         col.insertOne(doc);
        System.out.println("Inserted Successfully !!!");
        return "SUCCESS";

    }

But I encounter the following exception:

JBWEB000236: Servlet.service () for the CXFServlet servlet generated an exception: java.lang.NoSuchMethodError: javax.ws.rs.InternalServerErrorException.validate (Ljavax / ws / rs / core / Response; status / core / Response; Lj $ $;) Ljavax / WS / RS / core / response;

I can not solve this problem. Can someone please help me regarding this ...

+13
3

1: , api url .

2: "" ("Content-Type") "application/json" .

3: Body JSON (application/json) .

4: json

{
  "name": "dummy",
  "marks": "26"
}

check the attached sample example image

+26

POSTMAN V5.2.0

URL: http://localhost: 8080/mail/user/register/

JSON:

{"name":"John","firstName":"Smith","lastName":"MT","email":"johnsmt@yahoo.com"}

:

key: content-type
value: application/json
  1. JSON , BODYrawJSON (application/json)

  2. "" JSON/XML....

:

  1. URL REST Spring
@RestController

@RequestMapping("/user")
  1. URL
@RequestMapping(value = "/register", method = RequestMethod.POST, produces="application/json", consumes="application/json")
+8

I had the same problem that was solved by importing the dependency jersey.jsonand adding it toweb.xml

<init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
0
source

Source: https://habr.com/ru/post/1651395/


All Articles