I/O问题没有为类org.json.JSONObject找到序列化程序,也没有发现创建BeanSerializer的属性 [英] Issue with i/o No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer
问题描述
不确定发生了什么,完整的错误是:
not sure whats going on, the full error is:
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) )
我正在尝试将PUT请求发送到RESTful服务.我正在解析POST,并为PUT发送修改后的"ID"和"enabled"键/值对.
I am trying to send a PUT request to a RESTful service. I am parsing a POST And sending modified key/value pairs for 'ID' and 'enabled' for the 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是一个全局变量,它是从POST解析的ID.
createUserID is a global variable that is the ID parsed from the POST.
正在解析的JSON文件如下所示:
JSON file that is getting parsed looks like this:
{
"enabled" : false,
"_id" : "fdse332a-22432d-4432b"
}
在之前的测试方法中,我使用所有适当的url端点设置了放心的东西...
In a before test method I am setting up the restassured with all the appropriate url endpoints...
此外,PUT也失败,并出现NULLPointerException错误.那可能是将来的另一篇文章!
Also, the PUT is also failing, with a NULLPointerException Error. That may be another post in the future!
推荐答案
解决方案:传递给我保证时,我没有将JSON对象转换为字符串.
Solution: I was not converting my JSON object to a string when passing to restassured.
String responseJson = given().body(jsonObjPut.toString).
这成功了.现在,我用生成的ID修改现有的json,并在RESTful服务上成功执行PUT.
This did the trick. I now modify my existing json with generated ID and do a successful PUT on the RESTful service.
这篇关于I/O问题没有为类org.json.JSONObject找到序列化程序,也没有发现创建BeanSerializer的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!