InvalidDefinitionException: «Аргумент № 0 конструктора не имеет имени свойства»JAVA

Программисты JAVA общаются здесь
Anonymous
InvalidDefinitionException: «Аргумент № 0 конструктора не имеет имени свойства»

Сообщение Anonymous »

У меня проблемы с деессериализацией JSON. У моего класса DTO есть специальный частный конструктор для этого. Я аннотировал его с помощью @jsoncreator
@Getter
public class QuestionCommentResponseDto {
private final Long id;
private final Long questionId;
private final LocalDateTime createdDate;
private final LocalDateTime modifiedDate;
private final String text;
@Setter
private AccountResponseDto owner;

public QuestionCommentResponseDto(Long id, Long questionId, LocalDateTime createdDate,
LocalDateTime modifiedDate, String text) {
this.id = id;
this.questionId = questionId;
this.createdDate = createdDate;
this.modifiedDate = modifiedDate;
this.text = text;
}
@JsonCreator
private QuestionCommentResponseDto(Long id, Long questionId, LocalDateTime createdDate,
LocalDateTime modifiedDate, String text,
AccountResponseDto owner) {
this(id, questionId, createdDate, modifiedDate, text);
this.owner = owner;
}
// equals() and hashcode()
}
< /code>
// the associated DTO
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class AccountResponseDto {

private Long id;
private String username;
// equals() and hashcode()
< /code>
По какой -то причине Джексон не может использовать назначенный конструктор. Сообщение об ошибке неясно < /p>
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Invalid type definition for type `stack.overflow.model.dto.response.QuestionCommentResponseDto`: Argument #0 of constructor [constructor for `stack.overflow.model.dto.response.QuestionCommentResponseDto` (6 args), annotations: {interface com.fasterxml.jackson.annotation.JsonCreator=@com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT)} has no property name (and is not Injectable): can not use as property-based Creator
at [Source: (String)"{"data":{"id":1,"questionId":1,"createdDate":"2023-06-03T20:16:57.238883","modifiedDate":"2023-06-03T20:16:57.238883","text":"text","owner":{"id":1,"username":"mickey_m"}}}"; line: 1, column: 1]
< /code>
Что это значит? Что такое "Аргумент № 0"? "идентификатор"? Как это проблематично? Он идеально соответствует поле по имени и введите, поэтому я ожидаю, что Джексон будет достаточно умным, чтобы составить их вместе. И самое главное, Как мне решить эту проблему?>

Подробнее здесь: https://stackoverflow.com/questions/763 ... perty-name

Вернуться в «JAVA»