Skip to content

Commit 82dbaf6

Browse files
authored
Implement #1564: Add SimpleStreamReadContext.rollbackValueRead() method (#1565)
1 parent 36dc53a commit 82dbaf6

File tree

4 files changed

+17
-48
lines changed

4 files changed

+17
-48
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ JSON library.
2222
#1544: Validate `read()` parameters in `MergedStream` and `UTF32Reader`
2323
(implemented by @pjfanning)
2424
#1545: Increase Android baseline from 26 to 34 in Jackson 3.2
25+
#1564: Add `SimpleStreamReadContext.rollbackValueRead()` method
2526

2627
3.1.1 (not yet released)
2728

src/main/java/tools/jackson/core/util/SimpleStreamReadContext.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,6 @@ public SimpleStreamReadContext(int type, SimpleStreamReadContext parent, int nes
6464
_index = -1;
6565
}
6666

67-
// REMOVE as soon as nothing uses this
68-
@Deprecated
69-
public SimpleStreamReadContext(int type, SimpleStreamReadContext parent,
70-
DupDetector dups,
71-
int lineNr, int colNr) {
72-
super();
73-
_parent = parent;
74-
_dups = dups;
75-
_type = type;
76-
_lineNr = lineNr;
77-
_columnNr = colNr;
78-
_index = -1;
79-
_nestingDepth = -1;
80-
}
81-
8267
protected void reset(int type, int lineNr, int colNr) {
8368
_type = type;
8469
_currentValue = null;
@@ -205,6 +190,21 @@ public int valueRead() {
205190
return ++_index; // starts from -1
206191
}
207192

193+
/**
194+
* Method to call to "undo" previous call to {@link #valueRead()}; will
195+
* decrement {@code _index} unless it is already negative.
196+
*
197+
* @return Index after rollback
198+
*
199+
* @since 3.2
200+
*/
201+
public int rollbackValueRead() {
202+
if (_index >= 0) {
203+
--_index;
204+
}
205+
return _index;
206+
}
207+
208208
/**
209209
* Method called to indicate what the "current" name (Object property name
210210
* just decoded) is: may also trigger duplicate detection.

src/main/java/tools/jackson/core/util/SimpleStreamWriteContext.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,6 @@ protected SimpleStreamWriteContext(int type, SimpleStreamWriteContext parent, in
6868
_currentValue = currentValue;
6969
}
7070

71-
// REMOVE as soon as nothing uses this
72-
/*
73-
@Deprecated
74-
protected SimpleStreamWriteContext(int type, SimpleStreamWriteContext parent,
75-
DupDetector dups, Object currentValue) {
76-
super();
77-
_type = type;
78-
_parent = parent;
79-
_dups = dups;
80-
_index = -1;
81-
_currentValue = currentValue;
82-
}
83-
*/
84-
8571
private SimpleStreamWriteContext reset(int type, Object currentValue) {
8672
_type = type;
8773
// Due to way reuse works, "_parent" and "_nestingDepth" are fine already
@@ -204,7 +190,7 @@ public boolean writeName(String name) throws StreamWriteException {
204190
private final void _checkDup(DupDetector dd, String name) throws StreamWriteException {
205191
if (dd.isDup(name)) {
206192
Object src = dd.getSource();
207-
throw new StreamWriteException(((src instanceof JsonGenerator) ? ((JsonGenerator) src) : null),
193+
throw new StreamWriteException(((src instanceof JsonGenerator jg) ? jg : null),
208194
"Duplicate Object property \""+name+"\"");
209195
}
210196
}

src/test/java/tools/jackson/core/unittest/util/SimpleStreamReadContextTest.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,6 @@ void nestedContexts()
244244
assertSame(object, innerArray.getParent());
245245
}
246246

247-
@Test
248-
void deprecatedConstructor()
249-
{
250-
// Test the deprecated constructor without nestingDepth parameter
251-
@SuppressWarnings("deprecation")
252-
SimpleStreamReadContext ctx = new SimpleStreamReadContext(
253-
SimpleStreamReadContext.TYPE_OBJECT,
254-
null,
255-
null,
256-
1,
257-
0
258-
);
259-
260-
assertTrue(ctx.inObject());
261-
assertNull(ctx.getParent());
262-
assertEquals(-1, ctx.getNestingDepth()); // Should be -1 when using deprecated constructor
263-
}
264-
265247
@Test
266248
void contextTypeDescriptions()
267249
{

0 commit comments

Comments
 (0)