FasterXML / FasterXML/jackson-databind

Add `MapperFeature` that allows defaulting creator properties as required

Open
#3,507 8 comments 0 reactions 0 assignees View on GitHub
3.x pr-welcome
Dominant language
Java
Stars
3.7k
Forks
1.5k
Avg merge
3d 6h
Merged PRs (30d)
28

Description

**Is your feature request related to a problem? Please describe.**

With `records` becoming more prevalent, the two suggested workarounds to make properties required would mean that most of the code in that record would actually deal with making Jackson behave:

```
public record Person(String firstName, String lastName) // all params optional

// workaround 1
public record Person(
@JsonProperty(required = true) String firstName,
@JsonProperty(required = true) String lastName)

// workaround 2
public record Person(String firstName, String lastName) {
public Person {
Objects.requireNonNull(firstName);
Objects.requireNonNull(firstName);
}
}
```

**Describe the solution you'd like**
A clear and concise description of what you want to happen

Flip the default, such that all properties not marked with `@JsonProperty(required = true)` or being `Optional` are required.

**Usage example**

```
public record Person(String firstName, String lastName) // all params required
```

**Additional context**

All people I encountered have been unaware of the current default behavior, and considered it unexpected/undesirable when they found out about it.

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.