Skip to content

Commit

Permalink
Fix #1378: rename JsonParser.getText() as .getString() (JSTEP-6)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 3, 2025
1 parent 839c40e commit 40c2a98
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ JSON library.
#1269: Change `JsonFactory.builder()` configuration of `RecyclerPool` to avoid
allocation default implementation (in 3.0)
#1364: JSTEP-6: rename `JsonLocation` as `TokenStreamLocation`
#1378: Rename `JsonParser.getText()` as `.getString()` [JSTEP-6]
- Rename `JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT` as `AUTO_CLOSE_CONTENT`
- Add `TreeCodec.nullNode()`, `TreeNode.isNull()` methods
- Change the way `JsonLocation.NA` is included in exception messages
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tools/jackson/core/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public int releaseBuffered(OutputStream out) throws JacksonException {
* @throws JacksonIOException for low-level read issues
* @throws tools.jackson.core.exc.StreamReadException for decoding problems
*/
public String nextTextValue() throws JacksonException {
public String nextStringValue() throws JacksonException {
return (nextToken() == JsonToken.VALUE_STRING) ? getText() : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ private final JsonToken _nextTokenNotInObject(int i) throws JacksonException
}
// note: identical to one in UTF8StreamJsonParser
@Override
public final String nextTextValue() throws JacksonException
public final String nextStringValue() throws JacksonException
{
if (_currToken == JsonToken.PROPERTY_NAME) { // mostly copied from '_nextAfterName'
_nameCopied = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ private final String _nextName() throws IOException
}

@Override
public String nextTextValue() throws JacksonException
public String nextStringValue() throws JacksonException
{
// two distinct cases; either got name and we know next type, or 'other'
if (_currToken == JsonToken.PROPERTY_NAME) { // mostly copied from '_nextAfterName'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ private final static int _padLastQuadNoCheck(int q, int mask) {
*/

@Override
public String nextTextValue() throws JacksonException
public String nextStringValue() throws JacksonException
{
// two distinct cases; either got name and we know next type, or 'other'
if (_currToken == JsonToken.PROPERTY_NAME) { // mostly copied from '_nextAfterName'
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/tools/jackson/core/json/JsonFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void test_createParser_InputStream() throws Exception
JsonParser jsonParser = new JsonFactory()
.createParser(ObjectReadContext.empty(), inputStream);

assertEquals(jsonParser.nextTextValue(), "value");
assertEquals(jsonParser.nextStringValue(), "value");
}

public void test_createParser_File() throws Exception
Expand All @@ -241,7 +241,7 @@ public void test_createParser_File() throws Exception
JsonParser jsonParser = new JsonFactory()
.createParser(ObjectReadContext.empty(), path.toFile());

assertEquals(jsonParser.nextTextValue(), "value");
assertEquals(jsonParser.nextStringValue(), "value");
}

public void test_createParser_Path() throws Exception
Expand All @@ -251,7 +251,7 @@ public void test_createParser_Path() throws Exception
JsonParser jsonParser = new JsonFactory()
.createParser(ObjectReadContext.empty(), path);

assertEquals(jsonParser.nextTextValue(), "value");
assertEquals(jsonParser.nextStringValue(), "value");
}

public void test_createParser_Url() throws Exception
Expand All @@ -261,7 +261,7 @@ public void test_createParser_Url() throws Exception
JsonParser jsonParser = new JsonFactory()
.createParser(ObjectReadContext.empty(), path.toUri().toURL());

assertEquals(jsonParser.nextTextValue(), "value");
assertEquals(jsonParser.nextStringValue(), "value");
}

public void test_createParser_Reader() throws Exception
Expand All @@ -270,7 +270,7 @@ public void test_createParser_Reader() throws Exception
JsonParser jsonParser = new JsonFactory()
.createParser(ObjectReadContext.empty(), reader);

assertEquals(jsonParser.nextTextValue(), "value");
assertEquals(jsonParser.nextStringValue(), "value");
}

public void test_createParser_ByteArray() throws Exception
Expand All @@ -279,7 +279,7 @@ public void test_createParser_ByteArray() throws Exception
JsonParser jsonParser = new JsonFactory()
.createParser(ObjectReadContext.empty(), bytes);

assertEquals(jsonParser.nextTextValue(), "value");
assertEquals(jsonParser.nextStringValue(), "value");
}

public void test_createParser_String() throws Exception
Expand All @@ -288,7 +288,7 @@ public void test_createParser_String() throws Exception
JsonParser jsonParser = new JsonFactory()
.createParser(ObjectReadContext.empty(), string);

assertEquals(jsonParser.nextTextValue(), "value");
assertEquals(jsonParser.nextStringValue(), "value");
}

public void test_createParser_CharArray() throws Exception
Expand All @@ -297,7 +297,7 @@ public void test_createParser_CharArray() throws Exception
JsonParser jsonParser = new JsonFactory()
.createParser(ObjectReadContext.empty(), chars);

assertEquals(jsonParser.nextTextValue(), "value");
assertEquals(jsonParser.nextStringValue(), "value");
}

public void test_createParser_DataInput() throws Exception
Expand All @@ -307,7 +307,7 @@ public void test_createParser_DataInput() throws Exception
JsonParser jsonParser = new JsonFactory()
.createParser(ObjectReadContext.empty(), dataInput);

assertEquals(jsonParser.nextTextValue(), "value");
assertEquals(jsonParser.nextStringValue(), "value");
}


Expand Down
18 changes: 9 additions & 9 deletions src/test/java/tools/jackson/core/read/NextXxxAccessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,32 +341,32 @@ private void _textNextText(int mode) throws Exception
{
final String DOC = a2q("{'a':'123','b':5,'c':[false,'foo']}");
JsonParser p = createParser(mode, DOC);
assertNull(p.nextTextValue());
assertNull(p.nextStringValue());
assertToken(JsonToken.START_OBJECT, p.currentToken());
assertNull(p.nextTextValue());
assertNull(p.nextStringValue());
assertToken(JsonToken.PROPERTY_NAME, p.currentToken());
assertEquals("a", p.currentName());

assertEquals("123", p.nextTextValue());
assertEquals("123", p.nextStringValue());
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
assertEquals("b", p.currentName());
assertNull(p.nextName());
assertToken(JsonToken.VALUE_NUMBER_INT, p.currentToken());

assertEquals("c", p.nextName());

assertNull(p.nextTextValue());
assertNull(p.nextStringValue());
assertToken(JsonToken.START_ARRAY, p.currentToken());
assertNull(p.nextTextValue());
assertNull(p.nextStringValue());
assertToken(JsonToken.VALUE_FALSE, p.currentToken());
assertEquals("foo", p.nextTextValue());
assertEquals("foo", p.nextStringValue());

assertNull(p.nextTextValue());
assertNull(p.nextStringValue());
assertToken(JsonToken.END_ARRAY, p.currentToken());
assertNull(p.nextTextValue());
assertNull(p.nextStringValue());
assertToken(JsonToken.END_OBJECT, p.currentToken());
if (mode != MODE_DATA_INPUT) {
assertNull(p.nextTextValue());
assertNull(p.nextStringValue());
assertNull(p.currentToken());
}
p.close();
Expand Down

0 comments on commit 40c2a98

Please sign in to comment.