From d9df2121068c62d28a3c9dc7aac5d5152a1ead4b Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Fri, 1 Oct 2021 14:17:17 +0200 Subject: [PATCH] introduce null-save JsonObjectBuilder.add and JsonGenerator.write methods #213 Signed-off-by: Jorge Bescos Gascon --- api/src/main/java/jakarta/json/JsonBuilderFactory.java | 6 ++++++ api/src/main/java/jakarta/json/JsonObjectBuilder.java | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/jakarta/json/JsonBuilderFactory.java b/api/src/main/java/jakarta/json/JsonBuilderFactory.java index 214bf762..486dd8d8 100644 --- a/api/src/main/java/jakarta/json/JsonBuilderFactory.java +++ b/api/src/main/java/jakarta/json/JsonBuilderFactory.java @@ -50,6 +50,12 @@ */ public interface JsonBuilderFactory { + /** + * Configuration property to ignore null values. All providers + * must support this property. The value of the property is boolean. + */ + public static final String IGNORE_ADDING_IF_NULL = "jakarta.json.JsonBuilderFactory.ignoreAddingIfNull"; + /** * Creates a {@code JsonObjectBuilder} instance that is used to build * {@link JsonObject}. diff --git a/api/src/main/java/jakarta/json/JsonObjectBuilder.java b/api/src/main/java/jakarta/json/JsonObjectBuilder.java index 2b99b87e..1dd5a4c4 100644 --- a/api/src/main/java/jakarta/json/JsonObjectBuilder.java +++ b/api/src/main/java/jakarta/json/JsonObjectBuilder.java @@ -86,8 +86,9 @@ * * * - *

This class does not allow null to be used as a name or - * value while building the JSON object + *

By default, this class does not allow null to be used as a name or + * value while building the JSON object. It is possible to change this behavior with configuration + * {@link JsonBuilderFactory#IGNORE_ADDING_IF_NULL} * * @see JsonArrayBuilder */