gpt4 book ai didi

java - 如何解决 com.fasterxml.jackson.databind.exc.MismatchedInputException?

转载 作者:行者123 更新时间:2023-11-30 05:42:07 39 4
gpt4 key购买 nike

我在尝试通过 Swagger 发布请求时收到以下错误。当我通过 Postman 执行此操作时,效果很好。

我正在使用 springBootVersion = '2.1.0.RELEASE',swaggerVersion = '2.9.2'。

这是我的 Json 映射类。数据导出.java

@XmlRootElement(name = "DataExport")
public class DataExport
{
@JsonProperty("engineName")
private String engineName;

@JsonProperty("searchQuery")
private String searchQuery;

public DataExport()
{
super();
}

public DataExport(String aEngineName, String aSearchQuery)
{
super();
this.engineName = aEngineName;
this.searchQuery = aSearchQuery;
}

RestController.java

@RequestMapping(value = "/export", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.TEXT_PLAIN_VALUE)
@ApiOperation(authorizations = {
@Authorization(value = "oauth") }, value = "Initiates the job for export", response = String.class)
@ApiResponses({ @ApiResponse(code = 200, message = "Request accepted."),
@ApiResponse(code = 500, message = "The export could not be started due to an internal server error.") })
public String getJobId(@RequestBody DataExport aDataExport, HttpServletResponse aResponse,
@Value("${com.xyz.dataexportmodule.defaultfilelocation}") final String aLocation)
throws Exception
{
LOG.info("Initializing export for Engine {} and Query {}", aDataExport.getEngineName(),
aDataExport.getSearchQuery());

String exportLocation = aLocation
....

我想传递这个 JSON{"引擎名称":"ABC",“搜索查询”:“*”

}

但我收到此错误:

2019-04-01 13:42:05,022 [https-jsse-nio-8443-exec-19] WARN  o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct an instance of `com.xyz.dataexportmodule.persistence.entity.DataExport` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('string'); 
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct an instance of `com.xyz.dataexportmodule.persistence.entity.DataExport` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('string')
at [Source: (PushbackInputStream); line: 1, column: 1]]

我无法弄清楚问题出在哪里,请有人帮忙。

P.s:我的 Swagger 截图

enter image description here

解决方案:在 DataExport 类中进行这些更改并删除 REST Controller 方法中的 Location 变量后,此问题得到解决。

@JsonIgnoreProperties(ignoreUnknown = true)
@ApiModel(value = "Data Export", description = "A JSON object corresponding to Data Export entity.")
public class DataExport
{
private String mEngineName;

private String mSearchQuery;

/**
* Default CTor.
*/
public DataExport()
{
}

@JsonCreator
public DataExport(@JsonProperty("engineName") String aEngineName,
@JsonProperty("searchQuery") String aSearchQuery)
{
mEngineName = aEngineName;
mSearchQuery = aSearchQuery;
}

最佳答案

你的截图显示你有两个 body ,这不可能是done .

我不知道你想做什么,但只是为了测试删除字段 aLocation,就可以了。

关于java - 如何解决 com.fasterxml.jackson.databind.exc.MismatchedInputException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55454965/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com