Added deserialization support for Double NaN, Infinity, and -Infinity
This commit is contained in:
parent
f33a84c223
commit
362a94ec74
File diff suppressed because it is too large
Load Diff
|
@ -1,64 +1,68 @@
|
|||
/* Generated By:JavaCC: Do not edit this line. JsonParserConstants.java */
|
||||
package com.google.gson;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
interface JsonParserConstants {
|
||||
|
||||
int EOF = 0;
|
||||
int E = 5;
|
||||
int DIGITS = 6;
|
||||
int NULL = 7;
|
||||
int BOOLEAN = 8;
|
||||
int IDENTIFIER = 9;
|
||||
int HEX_CHAR = 10;
|
||||
int UNICODE_CHAR = 11;
|
||||
int ESCAPE_CHAR = 12;
|
||||
int SINGLE_QUOTE_LITERAL = 13;
|
||||
int DOUBLE_QUOTE_LITERAL = 14;
|
||||
int QUOTE = 15;
|
||||
int ENDQUOTE = 17;
|
||||
int CHAR = 18;
|
||||
int CNTRL_ESC = 19;
|
||||
int HEX = 21;
|
||||
int HEX_ESC = 22;
|
||||
|
||||
int DEFAULT = 0;
|
||||
int STRING_STATE = 1;
|
||||
int ESC_STATE = 2;
|
||||
int HEX_STATE = 3;
|
||||
|
||||
String[] tokenImage = {
|
||||
"<EOF>",
|
||||
"\" \"",
|
||||
"\"\\t\"",
|
||||
"\"\\n\"",
|
||||
"\"\\r\"",
|
||||
"<E>",
|
||||
"<DIGITS>",
|
||||
"\"null\"",
|
||||
"<BOOLEAN>",
|
||||
"<IDENTIFIER>",
|
||||
"<HEX_CHAR>",
|
||||
"<UNICODE_CHAR>",
|
||||
"<ESCAPE_CHAR>",
|
||||
"<SINGLE_QUOTE_LITERAL>",
|
||||
"<DOUBLE_QUOTE_LITERAL>",
|
||||
"\"\\\"\"",
|
||||
"\"\\\\\"",
|
||||
"<ENDQUOTE>",
|
||||
"<CHAR>",
|
||||
"<CNTRL_ESC>",
|
||||
"\"u\"",
|
||||
"<HEX>",
|
||||
"<HEX_ESC>",
|
||||
"\"{\"",
|
||||
"\"}\"",
|
||||
"\",\"",
|
||||
"\":\"",
|
||||
"\"[\"",
|
||||
"\"]\"",
|
||||
"\"-\"",
|
||||
"\".\"",
|
||||
};
|
||||
|
||||
}
|
||||
/* Generated By:JavaCC: Do not edit this line. JsonParserConstants.java */
|
||||
package com.google.gson;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
interface JsonParserConstants {
|
||||
|
||||
int EOF = 0;
|
||||
int E = 5;
|
||||
int DIGITS = 6;
|
||||
int NULL = 7;
|
||||
int NAN = 8;
|
||||
int INFINITY = 9;
|
||||
int BOOLEAN = 10;
|
||||
int IDENTIFIER = 11;
|
||||
int HEX_CHAR = 12;
|
||||
int UNICODE_CHAR = 13;
|
||||
int ESCAPE_CHAR = 14;
|
||||
int SINGLE_QUOTE_LITERAL = 15;
|
||||
int DOUBLE_QUOTE_LITERAL = 16;
|
||||
int QUOTE = 17;
|
||||
int ENDQUOTE = 19;
|
||||
int CHAR = 20;
|
||||
int CNTRL_ESC = 21;
|
||||
int HEX = 23;
|
||||
int HEX_ESC = 24;
|
||||
|
||||
int DEFAULT = 0;
|
||||
int STRING_STATE = 1;
|
||||
int ESC_STATE = 2;
|
||||
int HEX_STATE = 3;
|
||||
|
||||
String[] tokenImage = {
|
||||
"<EOF>",
|
||||
"\" \"",
|
||||
"\"\\t\"",
|
||||
"\"\\n\"",
|
||||
"\"\\r\"",
|
||||
"<E>",
|
||||
"<DIGITS>",
|
||||
"\"null\"",
|
||||
"\"NaN\"",
|
||||
"\"Infinity\"",
|
||||
"<BOOLEAN>",
|
||||
"<IDENTIFIER>",
|
||||
"<HEX_CHAR>",
|
||||
"<UNICODE_CHAR>",
|
||||
"<ESCAPE_CHAR>",
|
||||
"<SINGLE_QUOTE_LITERAL>",
|
||||
"<DOUBLE_QUOTE_LITERAL>",
|
||||
"\"\\\"\"",
|
||||
"\"\\\\\"",
|
||||
"<ENDQUOTE>",
|
||||
"<CHAR>",
|
||||
"<CNTRL_ESC>",
|
||||
"\"u\"",
|
||||
"<HEX>",
|
||||
"<HEX_ESC>",
|
||||
"\"{\"",
|
||||
"\"}\"",
|
||||
"\",\"",
|
||||
"\":\"",
|
||||
"\"[\"",
|
||||
"\"]\"",
|
||||
"\"-\"",
|
||||
"\".\"",
|
||||
};
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -29,6 +29,8 @@ TOKEN : {
|
|||
<E : ["e","E"](["+","-"])?>
|
||||
| <DIGITS : (["0"-"9"])+>
|
||||
| <NULL : "null">
|
||||
| <NAN : "NaN">
|
||||
| <INFINITY : "Infinity">
|
||||
| <BOOLEAN : ("true" | "false")>
|
||||
| <IDENTIFIER : ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_"])* >
|
||||
| <#HEX_CHAR : ["a"-"f","A"-"F","0"-"9"]>
|
||||
|
@ -161,9 +163,12 @@ private JsonPrimitive JsonNumber() :
|
|||
String intpart = null,
|
||||
fracpart = null,
|
||||
exppart = null;
|
||||
JsonPrimitive value;
|
||||
}
|
||||
{
|
||||
intpart=JsonInt() [ fracpart=JsonFrac() ] [ exppart=JsonExp() ]
|
||||
LOOKAHEAD(2)
|
||||
(value=JsonSpecialNumbers()) {return value; } |
|
||||
(intpart=JsonInt() [ fracpart=JsonFrac() ] [ exppart=JsonExp() ])
|
||||
{
|
||||
Number n;
|
||||
if (exppart != null || fracpart != null) {
|
||||
|
@ -177,6 +182,15 @@ private JsonPrimitive JsonNumber() :
|
|||
}
|
||||
}
|
||||
|
||||
private JsonPrimitive JsonSpecialNumbers() :
|
||||
{
|
||||
boolean negative = false;
|
||||
}
|
||||
{
|
||||
(<NAN>) {return new JsonPrimitive(Double.NaN); } |
|
||||
(["-" {negative = true;}]<INFINITY>) {return new JsonPrimitive(negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY); }
|
||||
}
|
||||
|
||||
private String JsonInt() :
|
||||
{
|
||||
String digits;
|
||||
|
|
|
@ -360,12 +360,8 @@ public class PrimitiveTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testDoubleNaNDeserializationNotSupported() {
|
||||
try {
|
||||
gson.fromJson("NaN", Double.class);
|
||||
gson.fromJson("NaN", double.class);
|
||||
fail("Gson should not accept NaN for deserialization");
|
||||
} catch (JsonParseException expected) {
|
||||
}
|
||||
assertTrue(Double.isNaN(gson.fromJson("NaN", Double.class)));
|
||||
assertTrue(Double.isNaN(gson.fromJson("NaN", double.class)));
|
||||
}
|
||||
public void testFloatNaNSerializationNotSupported() {
|
||||
float nan = (float) Float.NaN;
|
||||
|
@ -378,12 +374,8 @@ public class PrimitiveTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testFloatNaNDeserializationNotSupported() {
|
||||
try {
|
||||
gson.fromJson("NaN", Float.class);
|
||||
gson.fromJson("NaN", float.class);
|
||||
fail("Gson should not accept NaN for deserialization");
|
||||
} catch (JsonParseException expected) {
|
||||
}
|
||||
assertTrue(Float.isNaN(gson.fromJson("NaN", Float.class)));
|
||||
assertTrue(Float.isNaN(gson.fromJson("NaN", float.class)));
|
||||
}
|
||||
|
||||
public void testBigDecimalNaNDeserializationNotSupported() {
|
||||
|
@ -405,12 +397,8 @@ public class PrimitiveTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testDoubleInfinityDeserializationNotSupported() {
|
||||
try {
|
||||
gson.fromJson("Infinity", Double.class);
|
||||
gson.fromJson("Infinity", double.class);
|
||||
fail("Gson should not accept positive infinity for deserialization");
|
||||
} catch (JsonParseException expected) {
|
||||
}
|
||||
assertTrue(Double.isInfinite(gson.fromJson("Infinity", Double.class)));
|
||||
assertTrue(Double.isInfinite(gson.fromJson("Infinity", double.class)));
|
||||
}
|
||||
|
||||
public void testFloatInfinitySerializationNotSupported() {
|
||||
|
@ -424,12 +412,8 @@ public class PrimitiveTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testFloatInfinityDeserializationNotSupported() {
|
||||
try {
|
||||
gson.fromJson("Infinity", Float.class);
|
||||
gson.fromJson("Infinity", float.class);
|
||||
fail("Gson should not accept positive infinity for deserialization");
|
||||
} catch (JsonParseException expected) {
|
||||
}
|
||||
assertTrue(Float.isInfinite(gson.fromJson("Infinity", Float.class)));
|
||||
assertTrue(Float.isInfinite(gson.fromJson("Infinity", float.class)));
|
||||
}
|
||||
|
||||
public void testBigDecimalInfinityDeserializationNotSupported() {
|
||||
|
@ -451,12 +435,8 @@ public class PrimitiveTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testNegativeInfinityDeserializationNotSupported() {
|
||||
try {
|
||||
gson.fromJson("-Infinity", double.class);
|
||||
gson.fromJson("-Infinity", Double.class);
|
||||
fail("Gson should not accept positive infinity for deserialization");
|
||||
} catch (JsonParseException expected) {
|
||||
}
|
||||
assertTrue(Double.isInfinite(gson.fromJson("-Infinity", double.class)));
|
||||
assertTrue(Double.isInfinite(gson.fromJson("-Infinity", Double.class)));
|
||||
}
|
||||
|
||||
public void testNegativeInfinityFloatSerializationNotSupported() {
|
||||
|
@ -470,12 +450,8 @@ public class PrimitiveTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testNegativeInfinityFloatDeserializationNotSupported() {
|
||||
try {
|
||||
gson.fromJson("-Infinity", float.class);
|
||||
gson.fromJson("-Infinity", Float.class);
|
||||
fail("Gson should not accept positive infinity for deserialization");
|
||||
} catch (JsonParseException expected) {
|
||||
}
|
||||
assertTrue(Float.isInfinite(gson.fromJson("-Infinity", float.class)));
|
||||
assertTrue(Float.isInfinite(gson.fromJson("-Infinity", Float.class)));
|
||||
}
|
||||
|
||||
public void testNegativeInfinityBigDecimalDeserializationNotSupported() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user