@@ -8,6 +8,7 @@ public class NonStandardNumberParsingTest
8
8
{
9
9
private final JsonFactory JSON_F = JsonFactory .builder ()
10
10
.enable (JsonReadFeature .ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS )
11
+ .enable (JsonReadFeature .ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS )
11
12
.build ();
12
13
13
14
protected JsonFactory jsonFactory () {
@@ -30,6 +31,22 @@ public void testLeadingDotInDecimal() throws Exception {
30
31
}
31
32
}
32
33
34
+ /**
35
+ * The format "NNN." (as opposed to "NNN") is not valid JSON, so this should fail
36
+ */
37
+ public void testTrailingDotInDecimal () throws Exception {
38
+ for (int mode : ALL_MODES ) {
39
+ JsonParser p = createParser (mode , " 123. " );
40
+ try {
41
+ p .nextToken ();
42
+ fail ("Should not pass" );
43
+ } catch (JsonParseException e ) {
44
+ verifyException (e , "Decimal point not followed by a digit" );
45
+ }
46
+ p .close ();
47
+ }
48
+ }
49
+
33
50
public void testLeadingDotInDecimalAllowedAsync () throws Exception {
34
51
_testLeadingDotInDecimalAllowed (jsonFactory (), MODE_DATA_INPUT );
35
52
}
@@ -43,6 +60,19 @@ public void testLeadingDotInDecimalAllowedReader() throws Exception {
43
60
_testLeadingDotInDecimalAllowed (jsonFactory (), MODE_READER );
44
61
}
45
62
63
+ public void testTrailingDotInDecimalAllowedAsync () throws Exception {
64
+ _testTrailingDotInDecimalAllowed (jsonFactory (), MODE_DATA_INPUT );
65
+ }
66
+
67
+ public void testTrailingDotInDecimalAllowedBytes () throws Exception {
68
+ _testTrailingDotInDecimalAllowed (jsonFactory (), MODE_INPUT_STREAM );
69
+ _testTrailingDotInDecimalAllowed (jsonFactory (), MODE_INPUT_STREAM_THROTTLED );
70
+ }
71
+
72
+ public void testTrailingDotInDecimalAllowedReader () throws Exception {
73
+ _testTrailingDotInDecimalAllowed (jsonFactory (), MODE_READER );
74
+ }
75
+
46
76
private void _testLeadingDotInDecimalAllowed (JsonFactory f , int mode ) throws Exception
47
77
{
48
78
JsonParser p = createParser (f , mode , " .125 " );
@@ -52,4 +82,14 @@ private void _testLeadingDotInDecimalAllowed(JsonFactory f, int mode) throws Exc
52
82
assertEquals (".125" , p .getText ());
53
83
p .close ();
54
84
}
85
+
86
+ private void _testTrailingDotInDecimalAllowed (JsonFactory f , int mode ) throws Exception
87
+ {
88
+ JsonParser p = createParser (f , mode , " 125. " );
89
+ assertEquals (JsonToken .VALUE_NUMBER_FLOAT , p .nextToken ());
90
+ assertEquals (125.0 , p .getValueAsDouble ());
91
+ assertEquals ("125" , p .getDecimalValue ().toString ());
92
+ assertEquals ("125." , p .getText ());
93
+ p .close ();
94
+ }
55
95
}
0 commit comments