FasterXML / FasterXML/jackson-databind

It would be good if custom annotations from value class were used for Builder too

オープン
#2,391 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る
builder-related
主要言語
Java
スター
3.7k
フォーク
1.5k
平均マージ
3日 6時間
マージ済み PR(30日)
28

説明

Hi!
Maybe this is more a feature request but currently you have to add custom annotations (JacksonAnnotationsInside) to the builder class as well do make deserialization work, e.g.:

```java
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside
@JsonSerialize(using = SpecialSnowflakeSerializer.class)
@JsonDeserialize(using = SpecialSnowflakeDeserializer.class)
public @interface CustomAnnotation {

}
```
If I do some special stuff in SpecialSnowflake(De)Serializer classes, deserialization works only if I add `@CustomAnnotation` to the property in `Builder` as well. Duplication of code and error-prone IMHO. Maybe merge annotations from the "source" properties into the builder as it happens?

```java
@JsonDeserialize(builder = Person.Builder.class)
public final class Person {

@JsonPOJOBuilder(withPrefix = "")
public static final class Builder {

private String firstName;
private String lastName;

// @CustomAnnotation
private int age;

public Builder firstName(String firstName) {
this.firstName = firstName;
return this;
}

public Builder lastName(String lastName) {
this.lastName = lastName;
return this;
}

public Builder age(int age) {
this.age = age;
return this;
}

public Person build() {
return new Person(this);
}
}

private String firstName;
private String lastName;
@CustomAnnotation
private int age;

private Person(Builder builder) {
firstName = builder.firstName;
lastName = builder.lastName;
age = builder.age;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

@Override
public String toString() {
return "Person [firstName=" + firstName + ", lastName=" + lastName + ", age=" + age + "]";
}
}
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。