Skip to content

Commit

Permalink
Fix jackson initialization (#1984)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Nov 29, 2021
1 parent bdca953 commit 0713811
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class TelemetryChannel {

private static final Logger logger = LoggerFactory.getLogger(TelemetryChannel.class);

private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectMapper mapper = createObjectMapper();

private static final AppInsightsByteBufferPool byteBufferPool = new AppInsightsByteBufferPool();

Expand All @@ -76,10 +76,16 @@ public class TelemetryChannel {
// operationLogger?
private static final AtomicBoolean friendlyExceptionThrown = new AtomicBoolean();

static {
@SuppressWarnings("CatchAndPrintStackTrace")
private static ObjectMapper createObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.findAndRegisterModules();
// it's important to pass in the "agent class loader" since TelemetryChannel is initialized
// lazily and can be initialized via an application thread, in which case the thread context
// class loader is used to look up jsr305 module and its not found
mapper.registerModules(ObjectMapper.findModules(TelemetryChannel.class.getClassLoader()));
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
return mapper;
}

private final HttpPipeline pipeline;
Expand Down

0 comments on commit 0713811

Please sign in to comment.