简体   繁体   English

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

I am trying to send a PUT request to a RESTful service. 我正在尝试向RESTful服务发送PUT请求。 I am parsing a POST And sending modified key/value pairs for 'ID' and 'enabled' for the PUT. 我正在解析POST并为PUT发送'ID'和'enabled'的修改键/值对。

@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 the ID parsed from the POST. createUserID是一个全局变量,它是从POST解析的ID。

JSON file that is getting parsed looks like this: 正在解析的JSON文件如下所示:

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

In a before test method I am setting up the restassured with all the appropriate url endpoints... 在之前的测试方法中,我正在使用所有适当的url端点设置restassured ...

Also, the PUT is also failing, with a NULLPointerException Error. 此外,PUT也失败,出现NULLPointerException错误。 That may be another post in the future! 这可能是未来的另一篇文章!

Solution: I was not converting my JSON object to a string when passing to restassured. 解决方案:在传递给restassured时,我没有将我的JSON对象转换为字符串。

String responseJson = given().body(jsonObjPut.toString).

This did the trick. 这样做了。 I now modify my existing json with generated ID and do a successful PUT on the RESTful service. 我现在使用生成的ID修改现有的json,并在RESTful服务上成功执行PUT。

I was also facing same issue with java Spring rest Api. 我也遇到了与java Spring rest Api相同的问题。 It was throwing BeanSerializerExcption. 它正在抛出BeanSerializerExcption。 Use JsonNODE class instead of JSONObject . 使用JsonNODE类而不是JSONObject

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法编写 JSON:未找到类 org.json.JSONObject 的序列化程序,也未发现用于创建 BeanSerializer 的属性 - Could not write JSON: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer 收到此错误 No serializer found for class org.json.JSONObject 并且没有发现用于创建 BeanSerializer 的属性 - Getting this error No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer 找不到针对类org.json.JSONObject的序列化程序,也未找到创建BeanSerializer的属性 - No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer Jackson:没有找到 class ~~~~~ 的序列化器,也没有发现创建 BeanSerializer 的属性 - Jackson: No serializer found for class ~~~~~ and no properties discovered to create BeanSerializer 没有找到 class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor 的序列化程序,也没有发现创建 BeanSerializer 的属性 - No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer 无法编写 JSON:未找到类 java.io.FileDescriptor 的序列化程序,也未发现用于创建 BeanSerializer 的属性 - Could not write JSON: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer 没有为类java.util.logging.ErrorManager找到序列化程序,也没有发现创建BeanSerializer的属性 - No serializer found for class java.util.logging.ErrorManager and no properties discovered to create BeanSerializer 如何修复错误 No serializer found for class java.util.logging.SimpleFormatter and no properties found to create BeanSerializer - How to fix the error No serializer found for class java.util.logging.SimpleFormatter and no properties discovered to create BeanSerializer 使用 getValue 调用 Firebase 时,在类 org.json.JSONObject 上找不到要序列化的属性 - No properties to serialize found on class org.json.JSONObject when calling Firebase with getValue 未找到类型为org.json.JSONObject的返回值的转换器 - No converter found for return value of type: class org.json.JSONObject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM