FasterXML / FasterXML/jackson-databind

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

Abierto
#2,391 5 comentarios 0 reacciones 0 asignados Ver en GitHub
builder-related
Lenguaje dominante
Java
Estrellas
3.7k
Forks
1.5k
Merge medio
3 d 6 h
PR fusionados (30 d)
28

Descripción

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 + "]";
}
}
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.