我有一个 Spring Boot v1.5.14.RELEASE 应用程序,使用 Spring Initializer、JPA、嵌入式 Tomcat 并遵循 RESTful API 架构原则。我创建了这个测试@Test public void createCustomerChain() throws Exception { this.mockMvc.perform(post("/customer/createCustomer") .contentType(MediaType.APPLICATION_JSON_VALUE) .content("{\n" + " \"subSegment\":\"25\",\n" + " \"legalLanguage\":\"NL\",\n" + " \"isRestrictel\":true,\n" + " \"isCommunicationLanguageForAllAccount\":true,\n" + " \"isAntiMarketing\":true,\n" + " \"hotelChain\":{\n" + " \"legalForm\":\"09\",\n" + " \"foundationDate\":\"2001-12-17T09:30:47Z\",\n" + " \"tradingName\":\"COMPANY NAME\",\n" + " \"printName\":\"TEST PRINT\",\n" + " \"naceCode\":\"16230\",\n" + " \"vatNumber\":\"41223334343\", \n" + " \"countryVatCode\":\"IN\",\n" + " \"isSubjectToVAT\":true,\n" + " \"sectorCode\":\"85\",\n" + " \"legalAddress\": {\n" + " \"mainkey\":2088512,\n" + " \"subkey\":3256\n" + }这是运行测试的结果:org.springframework.restdocs.snippet.SnippetException: Fields with the following paths were not found in the payload: [customerId]customerId并从测试中删除fieldWithPath成功通过但是,我想知道为什么我对这样的字段没有相同的错误billingAccountId
1 回答
当年话下
TA贡献1890条经验 获得超9个赞
这是由于在某些情况下customerId
可能存在null
或不存在字段。您可以使用optional
它:
fieldWithPath("customerId").description("Description").optional()
为了找到更准确的原因,请发布该createCustomer()
方法的代码。
添加回答
举报
0/150
提交
取消