0

I'm trying to set the custom deserialization for my object.

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CtlEntity {
  @JsonProperty("id")
  private int id;  

  @JsonProperty("kids")
  @JsonDeserialize (using = ListDeserializer.class)
  private List<CtlEntity> kids;

}

My deserializer is:

  public class ListDeserializer extends StdDeserializer {

     public ListDeserializer() {
         this(null);
     }
    public ListDeserializer(Class clazz) {
        super(clazz);
    }

    @Override
    public List<CtlEntity> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        InnerItems innerItems = jsonParser.readValueAs(InnerItems.class);
        return innerItems.elements;
    }
    private class InnerItems {
        public List<CtlEntity> elements;
    }
  }

So I locate my ListDeserializer in CtlEntity as inner class.

But receive the error:

com.fasterxml.jackson.databind.JsonMappingException: Class ru.sber.entity.model.CtlEntity$ListDeserializer has no default (no arg) constructor

This answer is not usefull for me: CustomDeserializer has no default (no arg) constructor

Jelly
  • 972
  • 1
  • 17
  • 40
  • Not sure why you put ListDeserializer as an inner class, it should be a top level class or static nested class. Read https://stackoverflow.com/questions/70324/java-inner-class-and-static-nested-class to understand why you see the error. – samabcde Aug 23 '23 at 15:47

0 Answers0