Cannot construct instance of - Jackson

后端 未结 5 1797
北恋
北恋 2020-12-01 05:11

I am using Jackson and I\'m having problems, when I try to deserialize an Object I get the following error:

com.fasterxml.jackson.databind.JsonMappingExcepti         


        
5条回答
  •  死守一世寂寞
    2020-12-01 05:31

    You need to use a concrete class and not an Abstract class while deserializing. if the Abstract class has several implementations then, in that case, you can use it as below-

      @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
        @JsonSubTypes({ 
          @Type(value = Bike.class, name = "bike"), 
          @Type(value = Auto.class, name = "auto"), 
          @Type(value = Car.class, name = "car")
        })
        public abstract class Vehicle {
            // fields, constructors, getters, setters
        }
    

提交回复
热议问题