rest-Assured-解析json錯誤-需使用預定義的解析器解析

來源:互聯網
上載者:User

標籤: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錯誤-需使用預定義的解析器解析

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.