Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@JsonInclude should be equivalent to @JsonInclude(JsonInclude.Include.ALWAYS) #900

Open
sdelamo opened this issue Jul 26, 2024 · 0 comments

Comments

@sdelamo
Copy link
Contributor

sdelamo commented Jul 26, 2024

@JsonInclude(JsonInclude.Include.ALWAYS)

package mnserdenullable;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.serde.annotation.Serdeable;

@JsonInclude(JsonInclude.Include.ALWAYS)
@Serdeable
public record Book(@NonNull String title,
                   @Nullable  String author) {
}

For an object such as:

new Book("The Hobbit", null);

Renders:

{"title":"The Hobbit","author":null}

@JsonInclude

JsonInclude.Include.ALWAYS is the default value. However, if you use @JsonInclude instead of @JsonInclude(JsonInclude.Include.ALWAYS) it renders {"title":"The Hobbit"}

package mnserdenullable;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.serde.annotation.Serdeable;

@JsonInclude
@Serdeable
public record Book(@NonNull String title,
                   @Nullable  String author) {
}
@sdelamo sdelamo changed the title JsonInclude should be equivalent to @JsonInclude(JsonInclude.Include.ALWAYS) @JsonInclude should be equivalent to @JsonInclude(JsonInclude.Include.ALWAYS) Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant