You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2019/08/30 20:28:13 UTC

[GitHub] [logging-log4j2] IgorPerelyotov opened a new pull request #307: [LOG4J2-2652] JSON output wrong when using additonal fields

IgorPerelyotov opened a new pull request #307: [LOG4J2-2652] JSON output wrong when using additonal fields
URL: https://github.com/apache/logging-log4j2/pull/307
 
 
   Fix and tests for the issue https://issues.apache.org/jira/projects/LOG4J2/issues/LOG4J2-2652 
   
   The cause of the issue is: 
   1. Jackson is configured with custom serializer for Message added through setSerializer https://github.com/apache/logging-log4j2/blob/33009e1163227a20b526ac04b9af79b90d439bf5/log4j-layout-jackson/src/main/java/org/apache/logging/log4j/jackson/SimpleModuleInitializer.java#L24 
   2. Annotations for LogEvent is mixed through mix-in mechanism 
   3. MutableLogEvent implements both interfaces LogEvent and Message.
   
   When Jackson looking for an appropriate serializer for MutableLogEvent, it selects MessageSerializer and not UnwrappingBeanSerializer because MutableLogEvent implements Message.
   
   The bug report notes that the problem is not reproduced in 2,10 version. There was converting of MutableLogEvent to Log4jEvent and Log4jEvent implements single LogEvent interface,
   https://github.com/apache/logging-log4j2/blob/6275d8aac4e392eacd81d942a1b97856c92b698f/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java#L306
   
   As the fix I added JsonSerialize annotation with parameter "as" on the getter method in order to tell Jackson that the field must be serialized as LogEvent. Jackson will not consider MessageSerializer if actual type of this LogEvent is MutableLogEvent.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services