1. <legend id='k7Qzg'><style id='k7Qzg'><dir id='k7Qzg'><q id='k7Qzg'></q></dir></style></legend>

    <small id='k7Qzg'></small><noframes id='k7Qzg'>

  2. <tfoot id='k7Qzg'></tfoot>

    <i id='k7Qzg'><tr id='k7Qzg'><dt id='k7Qzg'><q id='k7Qzg'><span id='k7Qzg'><b id='k7Qzg'><form id='k7Qzg'><ins id='k7Qzg'></ins><ul id='k7Qzg'></ul><sub id='k7Qzg'></sub></form><legend id='k7Qzg'></legend><bdo id='k7Qzg'><pre id='k7Qzg'><center id='k7Qzg'></center></pre></bdo></b><th id='k7Qzg'></th></span></q></dt></tr></i><div id='k7Qzg'><tfoot id='k7Qzg'></tfoot><dl id='k7Qzg'><fieldset id='k7Qzg'></fieldset></dl></div>
    • <bdo id='k7Qzg'></bdo><ul id='k7Qzg'></ul>

      JsonMappingException:没有为类型 [简单类型,类] 找到

      时间:2023-07-26
      <legend id='LkzQ4'><style id='LkzQ4'><dir id='LkzQ4'><q id='LkzQ4'></q></dir></style></legend>
    1. <i id='LkzQ4'><tr id='LkzQ4'><dt id='LkzQ4'><q id='LkzQ4'><span id='LkzQ4'><b id='LkzQ4'><form id='LkzQ4'><ins id='LkzQ4'></ins><ul id='LkzQ4'></ul><sub id='LkzQ4'></sub></form><legend id='LkzQ4'></legend><bdo id='LkzQ4'><pre id='LkzQ4'><center id='LkzQ4'></center></pre></bdo></b><th id='LkzQ4'></th></span></q></dt></tr></i><div id='LkzQ4'><tfoot id='LkzQ4'></tfoot><dl id='LkzQ4'><fieldset id='LkzQ4'></fieldset></dl></div>

          1. <tfoot id='LkzQ4'></tfoot>
              <tbody id='LkzQ4'></tbody>
            • <bdo id='LkzQ4'></bdo><ul id='LkzQ4'></ul>

              <small id='LkzQ4'></small><noframes id='LkzQ4'>

                本文介绍了JsonMappingException:没有为类型 [简单类型,类] 找到合适的构造函数:无法从 JSON 对象实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我在尝试获取 JSON 请求并对其进行处理时收到以下错误:

                I am getting the following error when trying to get a JSON request and process it:

                org.codehaus.jackson.map.JsonMappingException:没有找到适合类型 [simple type, class com.myweb.ApplesDO] 的构造函数:无法从 JSON 对象实例化(需要添加/启用类型信息?)

                org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.myweb.ApplesDO]: can not instantiate from JSON object (need to add/enable type information?)

                这是我要发送的 JSON:

                Here is the JSON I am trying to send:

                {
                  "applesDO" : [
                    {
                      "apple" : "Green Apple"
                    },
                    {
                      "apple" : "Red Apple"
                    }
                  ]
                }
                

                在Controller中,我有以下方法签名:

                In Controller, I have the following method signature:

                @RequestMapping("showApples.do")
                public String getApples(@RequestBody final AllApplesDO applesRequest){
                    // Method Code
                }
                

                AllApplesDO 是 ApplesDO 的包装器:

                AllApplesDO is a wrapper of ApplesDO :

                public class AllApplesDO {
                
                    private List<ApplesDO> applesDO;
                
                    public List<ApplesDO> getApplesDO() {
                        return applesDO;
                    }
                
                    public void setApplesDO(List<ApplesDO> applesDO) {
                        this.applesDO = applesDO;
                    }
                }
                

                ApplesDO:

                public class ApplesDO {
                
                    private String apple;
                
                    public String getApple() {
                        return apple;
                    }
                
                    public void setApple(String appl) {
                        this.apple = apple;
                    }
                
                    public ApplesDO(CustomType custom){
                        //constructor Code
                    }
                }
                

                我认为 Jackson 无法将 JSON 转换为子类的 Java 对象.请帮助杰克逊将 JSON 转换为 Java 对象的配置参数.我正在使用 Spring 框架.

                I think that Jackson is unable to convert JSON into Java objects for subclasses. Please help with the configuration parameters for Jackson to convert JSON into Java Objects. I am using Spring Framework.

                在上述示例类中包含导致此问题的主要错误 - 请查看已接受的解决方案答案.

                Included the major bug that is causing this problem in the above sample class - Please look accepted answer for solution.

                推荐答案

                所以,我终于意识到问题所在了.这不是我怀疑的杰克逊配置问题.

                So, finally I realized what the problem is. It is not a Jackson configuration issue as I doubted.

                其实问题出在ApplesDO类:

                public class ApplesDO {
                
                    private String apple;
                
                    public String getApple() {
                        return apple;
                    }
                
                    public void setApple(String apple) {
                        this.apple = apple;
                    }
                
                    public ApplesDO(CustomType custom) {
                        //constructor Code
                    }
                }
                

                为该类定义了一个自定义构造函数,使其成为默认构造函数.引入虚拟构造函数使错误消失:

                There was a custom constructor defined for the class making it the default constructor. Introducing a dummy constructor has made the error to go away:

                public class ApplesDO {
                
                    private String apple;
                
                    public String getApple() {
                        return apple;
                    }
                
                    public void setApple(String apple) {
                        this.apple = apple;
                    }
                
                    public ApplesDO(CustomType custom) {
                        //constructor Code
                    }
                
                    //Introducing the dummy constructor
                    public ApplesDO() {
                    }
                
                }
                

                这篇关于JsonMappingException:没有为类型 [简单类型,类] 找到合适的构造函数:无法从 JSON 对象实例化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Java 中如何以及在何处使用注解? 下一篇:在 JPA 中设置列​​的默认值

                相关文章

                最新文章

              • <legend id='YiXsi'><style id='YiXsi'><dir id='YiXsi'><q id='YiXsi'></q></dir></style></legend>

                <small id='YiXsi'></small><noframes id='YiXsi'>

                <tfoot id='YiXsi'></tfoot>
                • <bdo id='YiXsi'></bdo><ul id='YiXsi'></ul>
                <i id='YiXsi'><tr id='YiXsi'><dt id='YiXsi'><q id='YiXsi'><span id='YiXsi'><b id='YiXsi'><form id='YiXsi'><ins id='YiXsi'></ins><ul id='YiXsi'></ul><sub id='YiXsi'></sub></form><legend id='YiXsi'></legend><bdo id='YiXsi'><pre id='YiXsi'><center id='YiXsi'></center></pre></bdo></b><th id='YiXsi'></th></span></q></dt></tr></i><div id='YiXsi'><tfoot id='YiXsi'></tfoot><dl id='YiXsi'><fieldset id='YiXsi'></fieldset></dl></div>