@@ -117,14 +117,22 @@ public Object process(Object input) {
117117
118118 String text = (String ) input ;
119119 if (text .trim ().isEmpty ()) {
120- return defaultValue != null ? defaultValue : input ;
120+ if (defaultValue != null ) {
121+ log .warn ("Input text is empty, returning default value" );
122+ return defaultValue ;
123+ }
124+ return input ;
121125 }
122126
123127 try {
124128 int start = findJsonStart (text );
125129 if (start < 0 ) {
130+ if (defaultValue != null ) {
131+ log .warn ("No JSON found in input text, returning default value" );
132+ return defaultValue ;
133+ }
126134 log .debug ("No JSON found in text" );
127- return defaultValue != null ? defaultValue : input ;
135+ return input ;
128136 }
129137
130138 JsonNode jsonNode = mapper .readTree (text .substring (start ));
@@ -133,16 +141,24 @@ public Object process(Object input) {
133141 if (jsonNode .isObject ()) {
134142 return mapper .convertValue (jsonNode , Map .class );
135143 }
144+ if (defaultValue != null ) {
145+ log .warn ("Expected JSON object but found {}, returning default value" , jsonNode .getNodeType ());
146+ return defaultValue ;
147+ }
136148 log .debug ("Expected JSON object but found {}" , jsonNode .getNodeType ());
137- return defaultValue != null ? defaultValue : input ;
149+ return input ;
138150 }
139151
140152 if (EXTRACT_TYPE_ARRAY .equalsIgnoreCase (extractType )) {
141153 if (jsonNode .isArray ()) {
142154 return mapper .convertValue (jsonNode , List .class );
143155 }
156+ if (defaultValue != null ) {
157+ log .warn ("Expected JSON array but found {}, returning default value" , jsonNode .getNodeType ());
158+ return defaultValue ;
159+ }
144160 log .debug ("Expected JSON array but found {}" , jsonNode .getNodeType ());
145- return defaultValue != null ? defaultValue : input ;
161+ return input ;
146162 }
147163
148164 // auto detect
@@ -153,12 +169,20 @@ public Object process(Object input) {
153169 return mapper .convertValue (jsonNode , List .class );
154170 }
155171
172+ if (defaultValue != null ) {
173+ log .warn ("JSON node is neither object nor array: {}, returning default value" , jsonNode .getNodeType ());
174+ return defaultValue ;
175+ }
156176 log .debug ("JSON node is neither object nor array: {}" , jsonNode .getNodeType ());
157- return defaultValue != null ? defaultValue : input ;
177+ return input ;
158178
159179 } catch (Exception e ) {
160- log .warn ("Failed to extract JSON from text: {}" , e .getMessage ());
161- return defaultValue != null ? defaultValue : input ;
180+ if (defaultValue != null ) {
181+ log .warn ("Failed to extract JSON from input text: {}, returning default value" , e .getMessage ());
182+ return defaultValue ;
183+ }
184+ log .warn ("Failed to extract JSON from input text: {}" , e .getMessage ());
185+ return input ;
162186 }
163187 }
164188
0 commit comments