FasterXML / FasterXML/jackson-databind

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

Open
#2,391 5 comments 0 reactions 0 assignees View on GitHub
builder-related
Dominant language
Java
Stars
3.7k
Forks
1.5k
Avg merge
3d 6h
Merged PRs (30d)
28

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.