@@ -35,11 +35,14 @@ protected DatabindException(Closeable processor, String msg, Throwable problem)
35
35
super (processor , msg , problem );
36
36
}
37
37
38
- protected DatabindException (Closeable processor , String msg , TokenStreamLocation loc )
39
- {
40
- super (msg , loc , null );
38
+ protected DatabindException (Closeable processor , String msg , TokenStreamLocation loc ) {
39
+ super (processor , msg , loc , null );
41
40
}
42
41
42
+ protected DatabindException (Closeable processor , String msg , TokenStreamLocation loc ,
43
+ Throwable rootCause ) {
44
+ super (processor , msg , loc , rootCause );
45
+ }
43
46
protected DatabindException (String msg , TokenStreamLocation loc , Throwable rootCause ) {
44
47
super (msg , loc , rootCause );
45
48
}
@@ -74,21 +77,62 @@ public static DatabindException from(DeserializationContext ctxt, String msg) {
74
77
return new DatabindException (_parser (ctxt ), msg );
75
78
}
76
79
80
+ public static DatabindException from (DeserializationContext ctxt , String msg , Throwable problem ) {
81
+ return new DatabindException (_parser (ctxt ), msg , problem );
82
+ }
83
+
84
+ public static DatabindException from (SerializationContext ctxt , String msg ) {
85
+ return new DatabindException (_generator (ctxt ), msg );
86
+ }
87
+
88
+ public static DatabindException from (SerializationContext ctxt , String msg , Throwable problem ) {
89
+ return new DatabindException (_generator (ctxt ), msg , problem );
90
+ }
91
+
77
92
// // "Overrides": methods with name same as ones from JacksonException
78
93
// // (but for static methods no real overriding, static dispatch)
79
94
80
95
public static JacksonException wrapWithPath (DeserializationContext ctxt ,
81
96
Throwable src , Reference ref ) {
82
- // !!! TODO: get `JsonParser`, location from `ctxt`
83
- return JacksonException .wrapWithPath (src , ref ,
84
- (msg , cause ) -> new DatabindException (msg , null , cause ));
97
+ JsonParser p = _parser (ctxt );
98
+
99
+ // Copied from JacksonException.wrapWithPath()
100
+ JacksonException jme ;
101
+ if (src instanceof JacksonException ) {
102
+ jme = (JacksonException ) src ;
103
+ } else {
104
+ // [databind#2128]: try to avoid duplication
105
+ String msg = _exceptionMessage (src );
106
+ // Let's use a more meaningful placeholder if all we have is null
107
+ if (msg == null || msg .isEmpty ()) {
108
+ msg = "(was " +src .getClass ().getName ()+")" ;
109
+ }
110
+ TokenStreamLocation loc = (p == null ) ? null : p .currentLocation ();
111
+ jme = new DatabindException (p , msg , loc , src );
112
+ }
113
+ jme .prependPath (ref );
114
+ return jme ;
85
115
}
86
116
87
117
public static JacksonException wrapWithPath (SerializationContext ctxt ,
88
118
Throwable src , Reference ref ) {
89
- // !!! TODO: get `JsonGenerator` from `ctxt`
90
- return JacksonException .wrapWithPath (src , ref ,
91
- (msg , cause ) -> new DatabindException (msg , null , cause ));
119
+ JsonGenerator g = _generator (ctxt );
120
+
121
+ // Copied from JacksonException.wrapWithPath()
122
+ JacksonException jme ;
123
+ if (src instanceof JacksonException ) {
124
+ jme = (JacksonException ) src ;
125
+ } else {
126
+ String msg = _exceptionMessage (src );
127
+ if (msg == null || msg .isEmpty ()) {
128
+ msg = "(was " +src .getClass ().getName ()+")" ;
129
+ }
130
+ // 2025-04-11, tatu: No location from generator, currently
131
+ TokenStreamLocation loc = null ;
132
+ jme = new DatabindException (g , msg , loc , src );
133
+ }
134
+ jme .prependPath (ref );
135
+ return jme ;
92
136
}
93
137
94
138
/*
@@ -101,16 +145,6 @@ private static JsonParser _parser(DeserializationContext ctxt) {
101
145
return (ctxt == null ) ? null : ctxt .getParser ();
102
146
}
103
147
104
- public static DatabindException from (SerializationContext ctxt , String msg ) {
105
- return new DatabindException (_generator (ctxt ), msg );
106
- }
107
-
108
- public static DatabindException from (SerializationContext ctxt , String msg , Throwable problem ) {
109
- // 17-Aug-2015, tatu: As per [databind#903] this is bit problematic as
110
- // SerializationContext instance does not currently hold on to generator...
111
- return new DatabindException (_generator (ctxt ), msg , problem );
112
- }
113
-
114
148
private static JsonGenerator _generator (SerializationContext ctxt ) {
115
149
return (ctxt == null ) ? null : ctxt .getGenerator ();
116
150
}
0 commit comments