FasterXML / jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
https://github.com/FasterXML/jackson
Apache License 2.0
1.03k stars 330 forks source link

@JsonCreator with constuctor, whitch parameters annotated with @JsonProperty #232

Closed nikitatishin5 closed 1 year ago

nikitatishin5 commented 1 year ago

I ran into an annotation behavior that is incomprehensible to me.

For example, if I try to deserialize an object with such a constructor, then if the fields are null, everything works and an exception is thrown.

 @JsonCreator
    public Person(String userId, String firstName, String birthDate) {
      this.userId = userId;
      this.lastName = lastName;
      this.birthDate = birthDate;
    }

But if the constructs look like this

 @JsonCreator
    public Person(@JsonProperty(value = "user_id", required = true) String userId,
                       @JsonProperty(value = "first_name", required = true) String firstName,
                       @JsonProperty(value = "birth_date", required = true) String birthDate

    ){
      this.userId = userId;
      this.lastName = lastName;
      this.birthDate = birthDate;
    }

then no validation occurs and no exception is thrown.

Is this the expected behavior?

Class fields are also annotated with @JsonProperty.

Jackson 2.13.2 version | Java 14