Add `JsonParser._constructReadException()` helper methods (Backport from 3.0)
@@ -2401,4 +2401,52 @@ public abstract class JsonParser
protected void _reportUnsupportedOperation() {
throw new UnsupportedOperationException("Operation not supported by parser of type "+getClass().getName());
}
+
+ /**
+ * Helper method for constructing {@link JsonParseException}
+ * based on current state of the parser.
+ *
+ * @param msg Base exception message to construct exception with
+ *
+ * @return Read exception (of type {@link JsonParseException}) constructed
+ *
+ * @since 2.13
+ */
+ protected JsonParseException _constructReadException(String msg) {
+ // In 3.0 will be actual `StreamReadException`...
+ return _constructError(msg);
+ }
+
+ protected JsonParseException _constructReadException(String msg, Object arg) {
+ return _constructReadException(String.format(msg, arg));
+ }
+
+ protected JsonParseException _constructReadException(String msg, Object arg1, Object arg2) {
+ return _constructReadException(String.format(msg, arg1, arg2));
+ }
+
+ protected JsonParseException _constructReadException(String msg,
+ Object arg1, Object arg2, Object arg3) {
+ return _constructReadException(String.format(msg, arg1, arg2, arg3));
+ }
+
+ /**
+ * Helper method for constructing {@link JsonParseException}
+ * based on current state of the parser and indicating that the given
+ * {@link Throwable} is the root cause.
+ *
+ * @param msg Base exception message to construct exception with
+ * @param t Root cause to assign
+ *
+ * @return Read exception (of type {@link JsonParseException}) constructed
+ *
+ * @since 2.13
+ */
+ protected JsonParseException _constructReadException(String msg, Throwable t) {
+ JsonParseException e = new JsonParseException(this, msg, t);
+ if (_requestPayload != null) {
+ e = e.withRequestPayload(_requestPayload);
+ }
+ return e;
+ }
}
