I would like to extend the basic entity to be compatible DynamoDB document, but I don't know how to extend the entity's child. Here is the code:
@Data
@Accessors(chain = true)
@ApiModel
public class Question {
@NotNull
@ApiModelProperty(value = "UUID", required = true)
private UUID id;
@NotBlank
private String name;
@ApiModelProperty(value = "List of answers")
private List<Answer> answers = Collections.emptyList();
}
@Data
@Accessors(chain = true)
@ParametersAreNonnullByDefault
public class Answer {
@NotNull
@ApiModelProperty(value = "Question key", required = true)
private UUID questionKey;
@NotBlank
@ApiModelProperty(value = "Answer in string format", required = true)
private String value;
}
Here is the extended Answer Dynamo Document:
@DynamoDBTable(tableName = "question")
public class QuestionDocument extends Question {
@DynamoDBHashKey
@DynamoDBAutoGeneratedKey
@Override
public UUID getId() {
return super.getId();
}
@DynamoDBAttribute
@Override
public Long getName() {
return super.getName();
}
@DynamoDBAttribute
@Override
// Here is the problem, I don't know how to properly override answers, because this method expect Answer output.
public Set<AnswerDocument> getAnswers() {
return super.getAnswers();
}
}
@DynamoDBDocument
@NoArgsConstructor
public class AnswerDocument extends Answer {
@DynamoDBAttribute
@Override
public Long getValue() {
return super.getValue();
}
}
The problem is that I don't know how to properly overide extended QuestionDocument's getAnswers() method to return AnswerDocument extended as well.
Pls put me on the right track, how to do it with the inheritance how it's shown on the example above.
Thank you in advance.