Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public final class JsonUtils {
}

public static void quoteAsString(CharSequence content, StringBuilder sb) {
if (content == null) {
sb.append("null");
return;
}
final int[] escCodes = sOutputEscapes128;
final int escLen = escCodes.length;
for (int i = 0, len = content.length(); i < len; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package co.elastic.logging;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -54,6 +55,13 @@ void serializeExceptionAsString() throws IOException {
assertThat(jsonNode.get("error.stack_trace").textValue()).isEqualTo(stringWriter.toString());
}

@Test
void serializeNullDoesNotThrowAnException() throws JsonProcessingException {
StringBuilder stringBuilder = new StringBuilder();
EcsJsonSerializer.serializeFormattedMessage(stringBuilder, null);
assertThat(stringBuilder.toString()).isEqualTo("\"message\":\"null\", ");
}

@Test
void serializeExceptionAsArray() throws IOException {
Exception exception = new Exception("foo");
Expand Down