Problem with i / o Serializer not found for class org.json.JSONObject and no properties found to create BeanSerializer

not sure what is going on, complete error:

Problem with i/o No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) 

I am trying to send a PUT request to a RESTful service. I parsed the POST and sent the modified key / value pairs for "ID" and "enabled" for PUT.

 @Test(dependsOnMethods= {"Post"}) public void Put() throws IOException { logger.logTestActivity("Testing FORM data POST using Excel file"); requestBuilder = new RequestSpecBuilder(); String jsonString = ""; boolean enabledModify = false; try { BufferedReader in = new BufferedReader(new FileReader( xmlTest.getParameter("json-post"))); String str; while ((str = in.readLine()) != null) { jsonString += str; } JSONObject jsonObjPut = new JSONObject(jsonString); jsonObjPut.put("_id", createUserId); jsonObjPut.put("enabled",enabledModify); System.out.println(jsonObjPut.toString()); in.close(); requestBuilder.setContentType(ContentType.JSON); requestSpecification = requestBuilder.build(); responseBuilder.expectStatusCode(Integer.parseInt(xmlTest .getParameter("http-status-code-200"))); responseBuilder.expectContentType(ContentType.JSON); responseSpecification = responseBuilder.build(); System.out.println(createUserId); String responseJson = given().body(jsonObjPut). when().put("/" + createUserId).asString(); System.out.println(responseJson); logger.logTestActivity("Finished testing FORM data POST using Excel file"); } catch (AssertionError e ) { logger.logTestActivity( "Error testing FORM data post: " + e.getMessage(),logger.ERROR); System.out.println("REST URL: " + RestAssured.baseURI + " " + RestAssured.port + " " + RestAssured.basePath ); Assert.fail("Error testing FORM data POST: " + e.getMessage()); throw e; } catch (IOException | JSONException e) { System.out.println("Problem with i/o" + e.getMessage()); } } 

createUserID is a global variable that is an identifier processed from POST.

The JSON file that is being processed is as follows:

 { "enabled" : false, "_id" : "fdse332a-22432d-4432b" } 

In the method before testing, I configure restassured with all the corresponding url endpoints ...

In addition, PUT also fails, with a NULLPointerException error. This may be another message in the future!

+4
source share
2 answers

Decision. I did not convert my JSON object to string when switching to restassured.

The answer to the line is Json = given (). body (jsonObjPut.toString). did the trick. Now I am modifying my existing json with the generated identifier and doing a successful PUT in a RESTful service.

+10
source

I also had a problem with java Spring rest Api. He is a metal BeanSerializerExcption. Use the JsonNODE class instead of JSONObject .

0
source

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


All Articles