File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
main/java/co/elastic/logging
test/java/co/elastic/logging Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,10 @@ public final class JsonUtils {
58
58
}
59
59
60
60
public static void quoteAsString (CharSequence content , StringBuilder sb ) {
61
+ if (content == null ) {
62
+ sb .append ("null" );
63
+ return ;
64
+ }
61
65
final int [] escCodes = sOutputEscapes128 ;
62
66
final int escLen = escCodes .length ;
63
67
for (int i = 0 , len = content .length (); i < len ; ++i ) {
Original file line number Diff line number Diff line change 24
24
*/
25
25
package co .elastic .logging ;
26
26
27
+ import com .fasterxml .jackson .core .JsonProcessingException ;
27
28
import com .fasterxml .jackson .databind .JsonNode ;
28
29
import com .fasterxml .jackson .databind .ObjectMapper ;
29
30
import org .junit .jupiter .api .Test ;
@@ -54,6 +55,13 @@ void serializeExceptionAsString() throws IOException {
54
55
assertThat (jsonNode .get ("error.stack_trace" ).textValue ()).isEqualTo (stringWriter .toString ());
55
56
}
56
57
58
+ @ Test
59
+ void serializeNullDoesNotThrowAnException () throws JsonProcessingException {
60
+ StringBuilder stringBuilder = new StringBuilder ();
61
+ EcsJsonSerializer .serializeFormattedMessage (stringBuilder , null );
62
+ assertThat (stringBuilder .toString ()).isEqualTo ("\" message\" :\" null\" , " );
63
+ }
64
+
57
65
@ Test
58
66
void serializeExceptionAsArray () throws IOException {
59
67
Exception exception = new Exception ("foo" );
You can’t perform that action at this time.
0 commit comments