码迷,mamicode.com
首页 > Web开发 > 详细

rest-Assured-解析json错误-需使用预定义的解析器解析

时间:2017-07-03 14:10:08      阅读:1349      评论:0      收藏:0      [点我收藏+]

标签:void   响应   lock   div   plain   5.0   tty   nal   public   

报错信息:

java.lang.IllegalStateException: Expected response body to be verified as JSON, HTML or XML but content-type ‘text/plain‘ is not supported out of the box.
Try registering a custom parser using:
RestAssured.registerParser("text/plain", <parser type>);

解决方案:

1.使用预定义解析器:RestAssured.registerParser("text/plain", Parser.JSON);


public static void registerParser(String  contentType, Parser  parser)
使用预定义的解析器注册要解析的自定义内容类型。例如,您希望使用XML解析器解析内容类型应用程序/自定义,以便能够使用XML点符号来验证响应:
 get(“/ x”)。then()。assertThat()。body(“document.child”,equalsTo(“something”))..
 
由于默认情况下,由于应用程序/自定义未被注册为由XML解析器处理,因此您需要在发出请求之前明确地告诉REST Assured使用此解析器:
 RestAssured.registerParser(“application / custom,Parser.XML”);
 
参数:
contentType - 要注册的内容类型
parser - 验证响应时使用的解析器。

rest-Assured-解析json错误-需使用预定义的解析器解析

标签:void   响应   lock   div   plain   5.0   tty   nal   public   

原文地址:http://www.cnblogs.com/lin-123/p/7110282.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!