Skip to content

Commit 601efdb

Browse files
committed
Merge branch '2.x' into 3.x
2 parents 8bdd258 + f0a2dee commit 601efdb

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

src/main/java/tools/jackson/dataformat/xml/deser/FromXmlParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public TokenStreamLocation currentLocation() {
372372
*/
373373

374374
/**
375-
* Since xml representation can not really distinguish between array
375+
* Since xml representation cannot really distinguish between array
376376
* and object starts (both are represented with elements), this method
377377
* is overridden and taken to mean that expectation is that the current
378378
* start element is to mean 'start array', instead of default of
@@ -403,7 +403,7 @@ public boolean isExpectedStartArrayToken()
403403
}
404404

405405
/**
406-
* Since xml representation can not really distinguish between different
406+
* Since xml representation cannot really distinguish between different
407407
* scalar types (numbers, booleans) -- they are all just Character Data,
408408
* without schema -- we can try to infer type from intent here.
409409
* The main benefit is avoiding checks for coercion.
@@ -917,7 +917,7 @@ public byte[] getBinaryValue(Base64Variant b64variant) throws JacksonException
917917
{
918918
if (_currToken != JsonToken.VALUE_STRING &&
919919
(_currToken != JsonToken.VALUE_EMBEDDED_OBJECT || _binaryValue == null)) {
920-
_reportError("Current token ("+_currToken+") not VALUE_STRING or VALUE_EMBEDDED_OBJECT, can not access as binary");
920+
_reportError("Current token ("+_currToken+") not VALUE_STRING or VALUE_EMBEDDED_OBJECT, cannot access as binary");
921921
}
922922
// To ensure that we won't see inconsistent data, better clear up state...
923923
if (_binaryValue == null) {
@@ -1062,7 +1062,7 @@ protected final void _checkNumericValue(int expType) throws JacksonException {
10621062
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
10631063
return;
10641064
}
1065-
throw _constructReadException("Current token (%s) not numeric, can not use numeric value accessors",
1065+
throw _constructReadException("Current token (%s) not numeric, cannot use numeric value accessors",
10661066
currentToken());
10671067
}
10681068

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package tools.jackson.dataformat.xml.deser;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import tools.jackson.core.*;
6+
import tools.jackson.core.exc.StreamReadException;
7+
8+
import tools.jackson.dataformat.xml.*;
9+
10+
import static org.junit.jupiter.api.Assertions.assertNull;
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.fail;
14+
15+
public class XmlNumberParsingGetType1433Test
16+
extends XmlTestUtil
17+
{
18+
private final XmlMapper XML_MAPPER = xmlMapper(false);
19+
20+
// Bit different for XML as there's rarely "native" number tokens
21+
@Test
22+
void getNumberType() throws Exception
23+
{
24+
JsonParser p;
25+
26+
p = _createParser("<root>123</root>");
27+
_verifyGetNumberTypeFail(p, "null");
28+
assertToken(JsonToken.START_OBJECT, p.nextToken());
29+
_verifyGetNumberTypeFail(p, "START_OBJECT");
30+
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
31+
_verifyGetNumberTypeFail(p, "PROPERTY_NAME");
32+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
33+
assertTrue(p.isExpectedNumberIntToken());
34+
assertToken(JsonToken.VALUE_NUMBER_INT, p.currentToken());
35+
assertEquals(JsonParser.NumberType.INT, p.getNumberType());
36+
assertToken(JsonToken.END_OBJECT, p.nextToken());
37+
_verifyGetNumberTypeFail(p, "END_OBJECT");
38+
assertNull(p.nextToken());
39+
_verifyGetNumberTypeFail(p, "null");
40+
p.close();
41+
_verifyGetNumberTypeFail(p, "null");
42+
}
43+
44+
private void _verifyGetNumberTypeFail(JsonParser p, String token) throws Exception
45+
{
46+
try {
47+
p.getNumberType();
48+
fail("Should not pass");
49+
} catch (StreamReadException e) {
50+
verifyException(e, "Current token ("+token+") not numeric, cannot use numeric");
51+
}
52+
}
53+
54+
private JsonParser _createParser(String text) throws Exception {
55+
return XML_MAPPER.createParser(text);
56+
}
57+
}

0 commit comments

Comments
 (0)