[英]HttpMessageNotReadableException: Could not read JSON: Unrecognized field using Spring boot and Android
I'm developing and web application which communicates with my Server.我正在开发与我的服务器通信的 web 应用程序。 This communication is done thru Spring framework and react js.
这种通信是通过 Spring 框架和 react js 完成的。 I'm sending an request for my server to read json but i got this error
我正在向我的服务器发送读取 json 的请求,但我收到此错误
error react console:错误反应控制台:
Uncaught (in promise) Error: Request failed with status code 400
未捕获(承诺中)错误:请求失败,状态码为 400
error spring boot:错误 spring 启动:
2020-08-10 11:54:34.550 WARN 22020 --- [nio-8080-exec-3].wsmsDefaultHandlerExceptionResolver: Resolved [org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message;
2020-08-10 11:54:34.550 WARN 22020 --- [nio-8080-exec-3].wsmsDefaultHandlerExceptionResolver:已解决 [org.springframework.http.converter.HttpMessageNotReadableException:读取输入消息时出现 I/O 错误; nested exception is java.io.IOException: Stream closed]
嵌套异常是 java.io.IOException: Stream 关闭]
image json:图片 json:
code react js:代码反应js:
constructor(props) {
super(props);
this.state = {
rfp: false,
rfx: false,
rfp_x: false,
allclassification: false,
eu : false,
americas: false,
aae: false,
ger: false,
eu2: false,
latam : false,
empty: false,
allregion: false,
}
this.onChange = this.onChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}
onChange(e) {
this.setState({ [e.target.name]: e.target.checked });
}
onSubmit(e) {
e.preventDefault();
const FilterClassification = {
// classification
rfx: this.state.rfx,
rfp: this.state.rfp,
rfp_x: this.state.rfp_x,
allclassification: this.state.allclassification
};
const FilterRegion = {
//Region
eu : this.state.eu,
americas : this.state.americas,
aae : this.state.aae,
ger: this.state.ger,
eu2 : this.state.eu2,
latam : this.state.latam,
empty : this.state.empty,
allregion : this.state.allregion,
}
console.log(FilterClassification);
console.log(FilterRegion);
axios.post("http://localhost:8080/MenuFiltre/filtreregioncloser",FilterClassification , FilterRegion )
}
Code java spring boot:代码 java spring 启动:
@PostMapping("/filtreregioncloser")
public Iterable<Closerfprfx>gettab1(@RequestBody FilterClassification FilterClassification , @RequestBody FilterRegion FilterRegion)
{
boolean rfx = FilterClassification.isRfx();
String ChaineRfx = "";
if(rfx==true)
{
ChaineRfx="rfx";
}else
{
ChaineRfx="xxxx";
}
boolean rfp =FilterClassification.isRfp() ;
String ChaineRfp = "";
if(rfp == true)
{
ChaineRfp="rfp";
}else
{
ChaineRfp="xxxx";
}
boolean rfp_x= FilterClassification.isRfp_x();
String ChaineRfp_x = "";
if(rfp_x==true)
{
ChaineRfp_x="rfp_x";
}else
{
ChaineRfp_x="xxxx";
}
boolean allclassification = FilterClassification.isAllclassification() ;
boolean eu = FilterRegion.isEu();
String ChaineEu= "";
if(eu==true)
{
ChaineEu="eu";
}else
{
ChaineEu="xxxx";
}
boolean americas = FilterRegion.isAmericas();
String ChaineAmericas = "";
if(americas==true)
{
ChaineAmericas="americas";
}
else {
ChaineAmericas="xxxx";
}
boolean aae = FilterRegion.isAae();
String ChaineAae = "";
if(aae==true)
{
ChaineAae="aae";
}else {
ChaineAae="xxxx";
}
boolean ger = FilterRegion.isGer();
String ChaineGer="";
if(ger==true)
{
ChaineGer="ger";
}else
{
ChaineGer="xxxx";
}
boolean eu2 = FilterRegion.isEu2();
String ChaineEu2="";
if(eu2=true)
{
ChaineEu2="eu2";
}else {
ChaineEu2="xxxx";
}
boolean latam = FilterRegion.isLatam() ;
String ChaineLatam = "";
if(latam=true)
{
ChaineLatam="latam";
}else {
ChaineLatam="xxxx";
}
boolean empty = FilterRegion.isEmpty();
String ChaineEmpty="";
if(empty=true)
{
ChaineEmpty="empty";
}else {
ChaineEmpty="xxxx";
}
boolean allregion = FilterRegion.isAllregion();
}
@RequestBody annotated parameter is expected to hold the entire body of the request and bind to one object
@RequestBody 注释参数预计会保存请求的整个正文并绑定到一个 object
I think u can't have more than one RequestBody in your parameters我认为你的参数中不能有多个 RequestBody
As mentioned above - you can't have 2 or more @RequestBody.如上所述 - 您不能拥有 2 个或更多 @RequestBody。 I recommend creating a wrapper class that will hold these parameters from these 2 classes of yours.
我建议创建一个包装器 class 来保存您的这两个类的这些参数。 Also get rid of this 'logic' from your controller layer... and get rid of these ifs... consider using pattern matching from vavr library since strategy pattern seems to be overkill there
还要从您的 controller 层中摆脱这种“逻辑”……并摆脱这些 ifs……考虑使用 vavr 库中的模式匹配,因为那里的策略模式似乎有点矫枉过正
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.