当前位置: 首页 > 知识库问答 >
问题:

HttpMessageNotreadableException:无法使用Spring boot和Android读取JSON:无法识别的字段

吕胤
2023-03-14

我正在开发与我的服务器通信的web应用程序。这种通信是通过Spring框架和react JS完成的。我正在发送一个请求,请求我的服务器读取json,但是我得到了这个错误

错误反应控制台:

未捕获(在promise中)错误:请求失败,状态代码为400

 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 )
  }
    @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();
}



 

共有1个答案

陶宜民
2023-03-14

如上所述-不能有2个或更多的@RequestBody。我建议创建一个包装类,它将保存您的这两个类中的这些参数。也摆脱这个‘逻辑’从您的控制器层...把这些如果扔掉...考虑使用vavr库中的模式匹配,因为策略模式似乎在那里被过度使用

 类似资料:
  • 下面是代码、json文件和我在执行代码时得到的异常。 //JSON //读取上述JSON格式时发生异常 04-18 07:07:09.089 314 44-31460/?E/DOINBackgroupExcp:无法读取JSON:无法解析日期值“i”(格式:“YYYY-MM-DD”):无法解析的日期:“i”(通过引用链:com.example.admin.myApplication.ShiftPla

  • 字符串不能解析为类型

  • 我有一个具有此结构的 xsd 文件: 所以,我已经用jaxb2生成了java类: Accesso 类和其他类也是如此。这是我尝试反序列化的xml文件的一个例子: 但是当我要反序列化某个xml文件时,我得到了这个错误: com.fasterxml.jackson.databind.exc.未识别的字段Accesso(类com.xx.yy.FlsProSoc),未标记为不可忽略(一个已知的属性:内容]

  • 我有一个这样的字符串,当我试图解析它时,它出现在JSON < code > processing data call \ \ u 007 fabc computers 中,jackson抛出一个这样的异常: 我认为问题的发生是因为。它在UTF-8中绝对有意义。知道如何避免这个问题吗?执行在这里有什么帮助吗?

  • 问题内容: 我遇到反序列化问题: 这是我的课: 我要反序列化的JSON是: 我得到这个异常: 我不想添加: 因为我想得到ResObj … 如果我添加了注释,它将通过,但会将其设置为null ..这是我不想要的。 问题答案: 如果您不想在bean中使用设置器,而只使用字段和获取器,则可以使用ObjectMapper的可见性检查器来允许字段可见。像下面这样

  • 我有一个与cassandra连接的springboot应用程序。我试图在地图中创建地图,但遇到以下异常。在我看来,即使我使用了冻结值,它仍在发送cal,但没有关键字冻结 错误 代码 马文