Skip to content

Commit 6a125c3

Browse files
committed
Warnings cleanup (getCurrentName() vs currentName() etc)
1 parent dda24a2 commit 6a125c3

File tree

7 files changed

+101
-89
lines changed

7 files changed

+101
-89
lines changed

src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java

+25-7
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public void addVirtualWrapping(Set<String> namesToWrap0, boolean caseInsensitive
473473
* the current event.
474474
*/
475475
@Override
476-
public String getCurrentName() throws IOException
476+
public String currentName() throws IOException
477477
{
478478
// start markers require information from parent
479479
String name;
@@ -490,6 +490,12 @@ public String getCurrentName() throws IOException
490490
return name;
491491
}
492492

493+
@Deprecated // since 2.17
494+
@Override
495+
public String getCurrentName() throws IOException {
496+
return currentName();
497+
}
498+
493499
@Override
494500
public void overrideCurrentName(String name)
495501
{
@@ -500,7 +506,7 @@ public void overrideCurrentName(String name)
500506
}
501507
ctxt.setCurrentName(name);
502508
}
503-
509+
504510
@Override
505511
public void close() throws IOException
506512
{
@@ -536,7 +542,7 @@ public XmlReadContext getParsingContext() {
536542
* that starts the current token.
537543
*/
538544
@Override
539-
public JsonLocation getTokenLocation() {
545+
public JsonLocation currentTokenLocation() {
540546
return _xmlTokens.getTokenLocation();
541547
}
542548

@@ -545,10 +551,22 @@ public JsonLocation getTokenLocation() {
545551
* usually for error reporting purposes
546552
*/
547553
@Override
548-
public JsonLocation getCurrentLocation() {
554+
public JsonLocation currentLocation() {
549555
return _xmlTokens.getCurrentLocation();
550556
}
551557

558+
@Deprecated // since 2.17
559+
@Override
560+
public JsonLocation getCurrentLocation() {
561+
return currentLocation();
562+
}
563+
564+
@Deprecated // since 2.17
565+
@Override
566+
public JsonLocation getTokenLocation() {
567+
return currentTokenLocation();
568+
}
569+
552570
/**
553571
* Since xml representation can not really distinguish between array
554572
* and object starts (both are represented with elements), this method
@@ -659,7 +677,7 @@ public JsonToken nextToken() throws IOException
659677
final String loc = (_parsingContext == null) ? "NULL" : String.valueOf(_parsingContext.pathAsPointer());
660678
switch (t) {
661679
case FIELD_NAME:
662-
System.out.printf("FromXmlParser.nextToken() at '%s': JsonToken.FIELD_NAME '%s'\n", loc, _parsingContext.getCurrentName());
680+
System.out.printf("FromXmlParser.nextToken() at '%s': JsonToken.FIELD_NAME '%s'\n", loc, _parsingContext.currentName());
663681
break;
664682
case VALUE_STRING:
665683
System.out.printf("FromXmlParser.nextToken() at '%s': JsonToken.VALUE_STRING '%s'\n", loc, getText());
@@ -874,7 +892,7 @@ public JsonToken nextToken() throws IOException
874892
@Override
875893
public String nextFieldName() throws IOException {
876894
if (nextToken() == JsonToken.FIELD_NAME) {
877-
return getCurrentName();
895+
return currentName();
878896
}
879897
return null;
880898
}
@@ -1027,7 +1045,7 @@ public String getText() throws IOException
10271045
}
10281046
switch (_currToken) {
10291047
case FIELD_NAME:
1030-
return getCurrentName();
1048+
return currentName();
10311049
case VALUE_STRING:
10321050
return _currText;
10331051
default:

src/main/java/com/fasterxml/jackson/dataformat/xml/ser/XmlSerializerProvider.java

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
1414
import com.fasterxml.jackson.databind.node.ObjectNode;
1515
import com.fasterxml.jackson.databind.ser.SerializerFactory;
16-
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.Impl;
1716
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
1817
import com.fasterxml.jackson.databind.util.TokenBuffer;
1918

src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ protected void verifyFieldName(JsonParser jp, String expName)
293293
throws IOException
294294
{
295295
assertEquals(expName, jp.getText());
296-
assertEquals(expName, jp.getCurrentName());
296+
assertEquals(expName, jp.currentName());
297297
}
298298

299299
protected void verifyException(Throwable e, String... matches)

src/test/java/com/fasterxml/jackson/dataformat/xml/lists/StringListRoundtripTest.java

+57-57
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,35 @@
1818
import static org.junit.Assert.assertNull;
1919

2020
// [dataformat-xml#584]
21-
public class StringListRoundtripTest {
22-
private final static String[] TEST_DATA = new String[] {"", "test", null, "test2"};
23-
24-
private final static XmlMapper MAPPER_READ_WRITE_NULLS = XmlMapper.builder()
25-
.enable(PROCESS_XSI_NIL)
26-
.enable(WRITE_NULLS_AS_XSI_NIL)
27-
.build();
28-
private final static XmlMapper MAPPER_READ_NULLS = XmlMapper.builder()
29-
.enable(PROCESS_XSI_NIL)
30-
.disable(WRITE_NULLS_AS_XSI_NIL)
31-
.build();
32-
private final static XmlMapper MAPPER_WRITE_NULLS = XmlMapper.builder()
33-
.disable(PROCESS_XSI_NIL)
34-
.enable(WRITE_NULLS_AS_XSI_NIL)
35-
.build();
36-
37-
@Test
38-
public void testStringArray() throws Exception
39-
{
40-
// default mode, should get back empty string
41-
_stringArrayRoundtrip(MAPPER_READ_NULLS, false);
42-
43-
// xsi null enabled, should get back null
44-
_stringArrayRoundtrip(MAPPER_READ_WRITE_NULLS, true);
45-
46-
// xsi null write enabled but processing disabled, should get back empty string
47-
_stringArrayRoundtrip(MAPPER_WRITE_NULLS, false);
48-
}
21+
public class StringListRoundtripTest
22+
{
23+
private final static String[] TEST_DATA = new String[] {"", "test", null, "test2"};
24+
25+
private final static XmlMapper MAPPER_READ_WRITE_NULLS = XmlMapper.builder()
26+
.enable(PROCESS_XSI_NIL)
27+
.enable(WRITE_NULLS_AS_XSI_NIL)
28+
.build();
29+
private final static XmlMapper MAPPER_READ_NULLS = XmlMapper.builder()
30+
.enable(PROCESS_XSI_NIL)
31+
.disable(WRITE_NULLS_AS_XSI_NIL)
32+
.build();
33+
private final static XmlMapper MAPPER_WRITE_NULLS = XmlMapper.builder()
34+
.disable(PROCESS_XSI_NIL)
35+
.enable(WRITE_NULLS_AS_XSI_NIL)
36+
.build();
37+
38+
@Test
39+
public void testStringArray() throws Exception
40+
{
41+
// default mode, should get back empty string
42+
_stringArrayRoundtrip(MAPPER_READ_NULLS, false);
43+
44+
// xsi null enabled, should get back null
45+
_stringArrayRoundtrip(MAPPER_READ_WRITE_NULLS, true);
46+
47+
// xsi null write enabled but processing disabled, should get back empty string
48+
_stringArrayRoundtrip(MAPPER_WRITE_NULLS, false);
49+
}
4950

5051
private void _stringArrayRoundtrip(ObjectMapper mapper, boolean shouldBeNull) throws Exception
5152
{
@@ -215,35 +216,34 @@ public void testStringMapPojo() throws Exception
215216
_stringMapPojoRoundtrip(MAPPER_WRITE_NULLS, false);
216217
}
217218

218-
private void _stringMapPojoRoundtrip(ObjectMapper mapper, boolean shouldBeNull) throws Exception
219-
{
220-
Map<String, String> map = new HashMap<String, String>() {{
221-
put("a", "");
222-
put("b", "test");
223-
put("c", null);
224-
put("d", "test2");
225-
}};
226-
MapPojo mapPojo = new MapPojo();
227-
mapPojo.setMap(map);
228-
229-
// serialize to string
230-
String xml = mapper.writeValueAsString(mapPojo);
231-
assertNotNull(xml);
232-
233-
// then bring it back
234-
MapPojo result = mapper.readValue(xml, MapPojo.class);
235-
assertEquals(4, result.map.size());
236-
assertEquals("", result.map.get("a"));
237-
assertEquals("test", result.map.get("b"));
238-
if (shouldBeNull)
239-
{
240-
assertNull(result.map.get("c"));
241-
} else
242-
{
243-
assertEquals("", result.map.get("c"));
244-
}
245-
assertEquals("test2", result.map.get("d"));
246-
}
219+
private void _stringMapPojoRoundtrip(ObjectMapper mapper, boolean shouldBeNull) throws Exception
220+
{
221+
@SuppressWarnings("serial")
222+
Map<String, String> map = new HashMap<String, String>() {{
223+
put("a", "");
224+
put("b", "test");
225+
put("c", null);
226+
put("d", "test2");
227+
}};
228+
MapPojo mapPojo = new MapPojo();
229+
mapPojo.setMap(map);
230+
231+
// serialize to string
232+
String xml = mapper.writeValueAsString(mapPojo);
233+
assertNotNull(xml);
234+
235+
// then bring it back
236+
MapPojo result = mapper.readValue(xml, MapPojo.class);
237+
assertEquals(4, result.map.size());
238+
assertEquals("", result.map.get("a"));
239+
assertEquals("test", result.map.get("b"));
240+
if (shouldBeNull) {
241+
assertNull(result.map.get("c"));
242+
} else {
243+
assertEquals("", result.map.get("c"));
244+
}
245+
assertEquals("test2", result.map.get("d"));
246+
}
247247

248248
static class MapPojo {
249249
Map<String, String> map;

src/test/java/com/fasterxml/jackson/dataformat/xml/stream/XmlParserNextXxxTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public void testXmlAttributesWithNextTextValue() throws Exception
3636
// First: verify handling without forcing array handling:
3737
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <data>
3838
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <max>
39-
assertEquals("max", xp.getCurrentName());
39+
assertEquals("max", xp.currentName());
4040

4141
assertEquals("7", xp.nextTextValue());
4242

4343
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <offset>
44-
assertEquals("offset", xp.getCurrentName());
44+
assertEquals("offset", xp.currentName());
4545

4646
assertEquals("offset", xp.getText());
4747

src/test/java/com/fasterxml/jackson/dataformat/xml/stream/XmlParserTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,21 @@ public void testForceElementAsArray() throws Exception
228228
// First: verify handling without forcing array handling:
229229
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <array>
230230
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <elem>
231-
assertEquals("elem", xp.getCurrentName());
231+
assertEquals("elem", xp.currentName());
232232
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
233233
assertEquals("value", xp.getText());
234234

235235
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <elem>
236-
assertEquals("elem", xp.getCurrentName());
236+
assertEquals("elem", xp.currentName());
237237
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <property>
238238
assertToken(JsonToken.FIELD_NAME, xp.nextToken());
239-
assertEquals("property", xp.getCurrentName());
239+
assertEquals("property", xp.currentName());
240240
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
241241
assertEquals("123", xp.getText());
242242
assertToken(JsonToken.END_OBJECT, xp.nextToken()); // <object>
243243

244244
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <elem>
245-
assertEquals("elem", xp.getCurrentName());
245+
assertEquals("elem", xp.currentName());
246246
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
247247
assertEquals("1", xp.getText());
248248

@@ -268,7 +268,7 @@ public void testForceElementAsArray() throws Exception
268268
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <property>
269269
assertTrue(xp.getParsingContext().inObject());
270270
assertToken(JsonToken.FIELD_NAME, xp.nextToken());
271-
assertEquals("property", xp.getCurrentName());
271+
assertEquals("property", xp.currentName());
272272
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
273273
assertEquals("123", xp.getText());
274274

@@ -298,12 +298,12 @@ public void testXmlAttributes() throws Exception
298298
// First: verify handling without forcing array handling:
299299
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <data>
300300
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <max>
301-
assertEquals("max", xp.getCurrentName());
301+
assertEquals("max", xp.currentName());
302302
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
303303
assertEquals("7", xp.getText());
304304

305305
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <offset>
306-
assertEquals("offset", xp.getCurrentName());
306+
assertEquals("offset", xp.currentName());
307307

308308
StringWriter w = new StringWriter();
309309
assertEquals(6, xp.getText(w));
@@ -344,15 +344,15 @@ public void testInferredNumbers() throws Exception
344344
assertEquals("abc", xp.getText());
345345

346346
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // @value2
347-
assertEquals("value2", xp.getCurrentName());
347+
assertEquals("value2", xp.currentName());
348348
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
349349
assertTrue(xp.isExpectedNumberIntToken());
350350
assertEquals(JsonToken.VALUE_NUMBER_INT, xp.currentToken());
351351
assertEquals(NumberType.INT, xp.getNumberType());
352352
assertEquals(42, xp.getIntValue());
353353

354354
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // implicit for text
355-
assertEquals("", xp.getCurrentName());
355+
assertEquals("", xp.currentName());
356356

357357
assertToken(JsonToken.VALUE_STRING, xp.nextToken());
358358
assertTrue(xp.isExpectedNumberIntToken());

src/test/java/com/fasterxml/jackson/dataformat/xml/stream/dos/DeepNestingParserTest.java

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.fasterxml.jackson.dataformat.xml.stream.dos;
22

33
import com.ctc.wstx.stax.WstxInputFactory;
4-
import com.fasterxml.jackson.core.JsonParseException;
4+
55
import com.fasterxml.jackson.core.JsonParser;
6-
import com.fasterxml.jackson.core.JsonToken;
6+
import com.fasterxml.jackson.core.exc.StreamReadException;
7+
78
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
89
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
910

@@ -14,12 +15,9 @@ public void testDeepDoc() throws Exception
1415
final XmlMapper xmlMapper = newMapper();
1516
final String XML = createDeepNestedDoc(1050);
1617
try (JsonParser p = xmlMapper.createParser(XML)) {
17-
JsonToken jt;
18-
while ((jt = p.nextToken()) != null) {
19-
20-
}
21-
fail("expected JsonParseException");
22-
} catch (JsonParseException e) {
18+
while (p.nextToken() != null) { }
19+
fail("expected StreamReadException");
20+
} catch (StreamReadException e) {
2321
assertTrue(e.getMessage().contains("Maximum Element Depth limit (1000) Exceeded"));
2422
}
2523
}
@@ -31,10 +29,7 @@ public void testDeepDocWithCustomDepthLimit() throws Exception
3129
final XmlMapper xmlMapper = new XmlMapper(wstxInputFactory);
3230
final String XML = createDeepNestedDoc(1050);
3331
try (JsonParser p = xmlMapper.createParser(XML)) {
34-
JsonToken jt;
35-
while ((jt = p.nextToken()) != null) {
36-
37-
}
32+
while (p.nextToken() != null) { }
3833
}
3934
}
4035

0 commit comments

Comments
 (0)