Deserializing JSON with Jackson - Why JsonMappingException “No suitable constructor”?

前端 未结 5 1809
眼角桃花
眼角桃花 2020-12-16 10:39

I have a problem deserializing a JSON string using Jackson (but I have no problem serializing an object to JSON).

Below I present the classes I use. The problem come

5条回答
  •  有刺的猬
    2020-12-16 11:23

    I was facing the issue and none of the answers worked for me. it seems the exception thrown is very generic one and is thrown for n number of causes. So one fix may not work for everyone. My case: we have a json response in which creditcard is a complex type but optional. when there is no creditcard data, we were getting an empty string in response:

    "creditcard":""

    But Credit card is a complex type for us:

    
                                    
                                        
                                            
                                            
                                            
                                        
                                    
                                
    

    We figured out, if there is no creditcard data, we should have something like this in json response:

    "creditcard":{}

    and not "creditcard":""

    it fixed this issue.

提交回复
热议问题