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 {
5858 }
5959
6060 public static void quoteAsString (CharSequence content , StringBuilder sb ) {
61+ if (content == null ) {
62+ sb .append ("null" );
63+ return ;
64+ }
6165 final int [] escCodes = sOutputEscapes128 ;
6266 final int escLen = escCodes .length ;
6367 for (int i = 0 , len = content .length (); i < len ; ++i ) {
Original file line number Diff line number Diff line change 2424 */
2525package co .elastic .logging ;
2626
27+ import com .fasterxml .jackson .core .JsonProcessingException ;
2728import com .fasterxml .jackson .databind .JsonNode ;
2829import com .fasterxml .jackson .databind .ObjectMapper ;
2930import org .junit .jupiter .api .Test ;
@@ -54,6 +55,13 @@ void serializeExceptionAsString() throws IOException {
5455 assertThat (jsonNode .get ("error.stack_trace" ).textValue ()).isEqualTo (stringWriter .toString ());
5556 }
5657
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+
5765 @ Test
5866 void serializeExceptionAsArray () throws IOException {
5967 Exception exception = new Exception ("foo" );
You can’t perform that action at this time.
0 commit comments