Skip to content

Commit b00ee12

Browse files
committed
Refactor toString() down to JsonStreamContext
1 parent ed27ed4 commit b00ee12

File tree

3 files changed

+37
-75
lines changed

3 files changed

+37
-75
lines changed

src/main/java/com/fasterxml/jackson/core/JsonStreamContext.java

+37
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package com.fasterxml.jackson.core;
77

8+
import com.fasterxml.jackson.core.io.CharTypes;
9+
810
/**
911
* Shared base class for streaming processing contexts used during
1012
* reading and writing of Json content using Streaming API.
@@ -247,4 +249,39 @@ public JsonPointer pathAsPointer(boolean includeRoot) {
247249
public JsonLocation getStartLocation(Object srcRef) {
248250
return JsonLocation.NA;
249251
}
252+
253+
/**
254+
* Overridden to provide developer readable "JsonPath" representation
255+
* of the context.
256+
*
257+
* @since 2.9
258+
*/
259+
@Override
260+
public String toString() {
261+
StringBuilder sb = new StringBuilder(64);
262+
switch (_type) {
263+
case TYPE_ROOT:
264+
sb.append("/");
265+
break;
266+
case TYPE_ARRAY:
267+
sb.append('[');
268+
sb.append(getCurrentIndex());
269+
sb.append(']');
270+
break;
271+
case TYPE_OBJECT:
272+
default:
273+
sb.append('{');
274+
String currentName = getCurrentName();
275+
if (currentName != null) {
276+
sb.append('"');
277+
CharTypes.appendQuoted(sb, currentName);
278+
sb.append('"');
279+
} else {
280+
sb.append('?');
281+
}
282+
sb.append('}');
283+
break;
284+
}
285+
return sb.toString();
286+
}
250287
}

src/main/java/com/fasterxml/jackson/core/json/JsonReadContext.java

-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fasterxml.jackson.core.json;
22

33
import com.fasterxml.jackson.core.*;
4-
import com.fasterxml.jackson.core.io.CharTypes;
54

65
/**
76
* Extension of {@link JsonStreamContext}, which implements
@@ -206,42 +205,4 @@ private void _checkDup(DupDetector dd, String name) throws JsonProcessingExcepti
206205
"Duplicate field '"+name+"'");
207206
}
208207
}
209-
210-
/*
211-
/**********************************************************
212-
/* Overridden standard methods
213-
/**********************************************************
214-
*/
215-
216-
/**
217-
* Overridden to provide developer readable "JsonPath" representation
218-
* of the context.
219-
*/
220-
@Override
221-
public String toString() {
222-
StringBuilder sb = new StringBuilder(64);
223-
switch (_type) {
224-
case TYPE_ROOT:
225-
sb.append("/");
226-
break;
227-
case TYPE_ARRAY:
228-
sb.append('[');
229-
sb.append(getCurrentIndex());
230-
sb.append(']');
231-
break;
232-
case TYPE_OBJECT:
233-
default:
234-
sb.append('{');
235-
if (_currentName != null) {
236-
sb.append('"');
237-
CharTypes.appendQuoted(sb, _currentName);
238-
sb.append('"');
239-
} else {
240-
sb.append('?');
241-
}
242-
sb.append('}');
243-
break;
244-
}
245-
return sb.toString();
246-
}
247208
}

src/main/java/com/fasterxml/jackson/core/json/JsonWriteContext.java

-36
Original file line numberDiff line numberDiff line change
@@ -204,40 +204,4 @@ public int writeValue() {
204204
++_index;
205205
return (_index == 0) ? STATUS_OK_AS_IS : STATUS_OK_AFTER_SPACE;
206206
}
207-
208-
// // // Internally used abstract methods
209-
210-
protected void appendDesc(StringBuilder sb) {
211-
if (_type == TYPE_OBJECT) {
212-
sb.append('{');
213-
if (_currentName != null) {
214-
sb.append('"');
215-
// !!! TODO: Name chars should be escaped?
216-
sb.append(_currentName);
217-
sb.append('"');
218-
} else {
219-
sb.append('?');
220-
}
221-
sb.append('}');
222-
} else if (_type == TYPE_ARRAY) {
223-
sb.append('[');
224-
sb.append(getCurrentIndex());
225-
sb.append(']');
226-
} else {
227-
// nah, ROOT:
228-
sb.append("/");
229-
}
230-
}
231-
232-
// // // Overridden standard methods
233-
234-
/**
235-
* Overridden to provide developer writeable "JsonPath" representation
236-
* of the context.
237-
*/
238-
@Override public String toString() {
239-
StringBuilder sb = new StringBuilder(64);
240-
appendDesc(sb);
241-
return sb.toString();
242-
}
243207
}

0 commit comments

Comments
 (0)