在Spring REST Docs中没有用于从字符串值('OK')反序列化的字符串参数构造函数/工厂方法

时间:2019-10-28 13:52:35

标签: spring spring-boot spring-mvc spring-rest spring-restdocs

我有一个使用Spring REST文档的springBoot 2.1.9.RELEASE应用程序。

我的TestController中有此方法,该方法返回ResponseEntity<HttpStatus>(HttpStatus.OK)

mockMvc.perform(post("/reservation-event")
                .content(convertToString(reservation))
                .contentType(APPLICATION_JSON))
                .andExpect(status().isOk())
                .andDo(document("create-reservation-event",

但是当我运行测试时,出现此错误:

org.springframework.restdocs.snippet.ModelCreationException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `java.util.LinkedHashMap` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('OK')
 at [Source: (byte[])""OK""; line: 1, column: 1]

我已更改为.andExpect(status().isCreated()),返回类型为return ok().body(HttpStatus.CREATED);,但随后出现此错误:

java.lang.AssertionError: Status 
Expected :201
Actual   :200

0 个答案:

没有答案