no-args constructor #172
-
Hi. I have a question regarding the case when there is no parameterless ("default") constructor. Does it still support the case where there is no parameterless ("default") constructor? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
I am guessing you are asking about specific module from https://github.com/FasterXML/jackson-modules-base/tree/2.16/no-ctor-deser It only needs to be used if you cannot annotate other constructors with Otherwise I am not quite sure what you are asking. |
Beta Was this translation helpful? Give feedback.
-
@cowtowncoder Thank you for your comment! Here is the dto class : @Getter
@AllArgsConstructor
@Builder
public class CartCreateDto {
private final Long productId;
private final int count;
public Cart toEntity(Long memberId) {
return Cart.builder()
.productId(getProductId())
.memberId(memberId)
.count(getCount())
.build();
}
} The above class satisfies both conditions: it does not require a no-arguments ("default") constructor and it does not have an @JsonCreator annotated constructor or factory method. Therefore, I didn't think @NoArgsConstructor was necessary. However, I'm encountering the following error.
Am I misunderstanding something? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
@cowtowncoder Thank you for your comment!
I am working on a project using Spring Boot version 2.7.9 and JDK 11.
When I execute the code to create a DTO class as follows, I encounter the following error.
Here is the dto class :
The above class satisfies both conditions: it does not require a no-arguments ("default") constructor and it does not have an @JsonCreator annotated constructor or…