Skip to content

Commit 00d5da7

Browse files
committed
provide NaN and Infinity when (de)serializing Java Numbers
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
1 parent e865594 commit 00d5da7

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

api/src/main/java/jakarta/json/stream/JsonGenerator.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ public interface JsonGenerator extends Flushable, /*Auto*/Closeable {
145145
*/
146146
String PRETTY_PRINTING = "jakarta.json.stream.JsonGenerator.prettyPrinting" ;
147147

148+
/**
149+
* Configuration property to generate NaN, +Infinity and -Infinity as nulls.
150+
*
151+
* @since 2.1
152+
*/
153+
String WRITE_NAN_AS_NULLS = "jakarta.json.stream.JsonGenerator.writeNanAsNulls";
154+
155+
/**
156+
* Configuration property to generate NaN, +Infinity and -Infinity as Strings.
157+
*
158+
* @since 2.1
159+
*/
160+
String WRITE_NAN_AS_STRINGS = "jakarta.json.stream.JsonGenerator.writeNanAsStrings";
161+
148162
/**
149163
* Writes the JSON start object character. It starts a new child object
150164
* context within which JSON name/value pairs can be written to the object.
@@ -336,9 +350,14 @@ public interface JsonGenerator extends Flushable, /*Auto*/Closeable {
336350
* @return this generator
337351
* @throws jakarta.json.JsonException if an i/o error occurs (IOException
338352
* would be cause of JsonException)
339-
* @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity.
353+
* @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity
354+
* when {@link JsonGenerator#WRITE_NAN_AS_NULLS} and/or {@link JsonGenerator#WRITE_NAN_AS_STRINGS}
355+
* is not set.
356+
*
340357
* @throws JsonGenerationException if this method is not called within an
341358
* object context
359+
*
360+
* @see {@link JsonGenerator#WRITE_NAN_AS_NULLS}, {@link JsonGenerator#WRITE_NAN_AS_STRINGS}
342361
*/
343362
JsonGenerator write(String name, double value);
344363

@@ -485,7 +504,11 @@ public interface JsonGenerator extends Flushable, /*Auto*/Closeable {
485504
* would be cause of JsonException)
486505
* @throws JsonGenerationException if this method is not called within an
487506
* array or root context.
488-
* @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity.
507+
* @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity
508+
* when {@link JsonGenerator#WRITE_NAN_AS_NULLS} and/or {@link JsonGenerator#WRITE_NAN_AS_STRINGS}
509+
* is not set.
510+
*
511+
* @see {@link JsonGenerator#WRITE_NAN_AS_NULLS}, {@link JsonGenerator#WRITE_NAN_AS_STRINGS}
489512
*/
490513
JsonGenerator write(double value);
491514

0 commit comments

Comments
 (0)