Skip to content

Commit 5c70fb1

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 3c3b1b1 commit 5c70fb1

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

api/src/main/java/jakarta/json/JsonConfig.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@
2323
*/
2424
public final class JsonConfig {
2525

26+
/**
27+
* Configuration property to generate JSON prettily. All providers
28+
* must support this property. The value of the property could be
29+
* be anything.
30+
*/
31+
String PRETTY_PRINTING = "jakarta.json.stream.JsonGenerator.prettyPrinting" ;
32+
33+
/**
34+
* Configuration property to generate NaN, +Infinity and -Infinity as nulls.
35+
*
36+
* @since 2.1
37+
*/
38+
String WRITE_NAN_AS_NULLS = "jakarta.json.stream.JsonGenerator.writeNanAsNulls";
39+
40+
/**
41+
* Configuration property to generate NaN, +Infinity and -Infinity as Strings.
42+
*
43+
* @since 2.1
44+
*/
45+
String WRITE_NAN_AS_STRINGS = "jakarta.json.stream.JsonGenerator.writeNanAsStrings";
46+
2647
/**
2748
* Configuration property to define the strategy for handling duplicate keys.
2849
*

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@
138138
* @see JsonGeneratorFactory
139139
*/
140140
public interface JsonGenerator extends Flushable, /*Auto*/Closeable {
141-
/**
142-
* Configuration property to generate JSON prettily. All providers
143-
* must support this property. The value of the property could be
144-
* be anything.
145-
*/
146-
String PRETTY_PRINTING = "jakarta.json.stream.JsonGenerator.prettyPrinting" ;
147141

148142
/**
149143
* Writes the JSON start object character. It starts a new child object
@@ -336,7 +330,9 @@ public interface JsonGenerator extends Flushable, /*Auto*/Closeable {
336330
* @return this generator
337331
* @throws jakarta.json.JsonException if an i/o error occurs (IOException
338332
* would be cause of JsonException)
339-
* @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity.
333+
* @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity
334+
* when {@link jakarta.json.JsonConfig#WRITE_NAN_AS_NULLS} and/or
335+
* {@link jakarta.json.JsonConfig#WRITE_NAN_AS_STRINGS} is not set.
340336
* @throws JsonGenerationException if this method is not called within an
341337
* object context
342338
*/
@@ -485,7 +481,9 @@ public interface JsonGenerator extends Flushable, /*Auto*/Closeable {
485481
* would be cause of JsonException)
486482
* @throws JsonGenerationException if this method is not called within an
487483
* array or root context.
488-
* @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity.
484+
* @throws NumberFormatException if the value is Not-a-Number (NaN) or infinity
485+
* when {@link jakarta.json.JsonConfig#WRITE_NAN_AS_NULLS} and/or
486+
* {@link jakarta.json.JsonConfig#WRITE_NAN_AS_STRINGS} is not set.
489487
*/
490488
JsonGenerator write(double value);
491489

0 commit comments

Comments
 (0)