Class LoggingDeserializationProblemHandler

java.lang.Object
com.fasterxml.jackson.databind.deser.DeserializationProblemHandler
org.kiwiproject.json.LoggingDeserializationProblemHandler

public class LoggingDeserializationProblemHandler extends com.fasterxml.jackson.databind.deser.DeserializationProblemHandler
A Jackson DeserializationProblemHandler that logs and keeps track of unknown properties during JSON deserialization. Any unexpected/unknown properties are logged as warnings and stored in-memory in a ConcurrentMap.

Optionally, you can supply a BiConsumer to the constructor if you want to be notified when unknown properties are encountered. This consumer should be thread-safe!

Note that jackson-core and jackson-databind must be available at runtime.

Implementation Note:
Currently the in-memory map will continue to grow unbounded. In the expected scenario, unknown properties will be relatively rare, so we don't expect huge numbers of them. In addition, only unique unknown properties are stored. The clearUnexpectedPaths() method is provided to allow clearing all unexpected paths, for example read the unexpected paths for analytics and then clear them.
  • Field Summary

    Fields inherited from class com.fasterxml.jackson.databind.deser.DeserializationProblemHandler

    NOT_HANDLED
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new instance with a no-op unknownPropertyConsumer.
    Create a new instance with the given unknownPropertyConsumer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear all unexpected path information.
    Return the unique unexpected paths in the format className -> propertyName.
    Return the unique unexpected paths in the format className.propertyName.
    long
    Current total count of unique unknown properties.
    boolean
    handleUnknownProperty(com.fasterxml.jackson.databind.DeserializationContext ctxt, com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.JsonDeserializer<?> deserializer, Object beanOrClass, String propertyName)
     

    Methods inherited from class com.fasterxml.jackson.databind.deser.DeserializationProblemHandler

    handleInstantiationProblem, handleMissingInstantiator, handleMissingInstantiator, handleMissingTypeId, handleUnexpectedToken, handleUnexpectedToken, handleUnknownTypeId, handleWeirdKey, handleWeirdNativeValue, handleWeirdNumberValue, handleWeirdStringValue

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LoggingDeserializationProblemHandler

      public LoggingDeserializationProblemHandler()
      Create a new instance with a no-op unknownPropertyConsumer.
    • LoggingDeserializationProblemHandler

      public LoggingDeserializationProblemHandler(BiConsumer<String,Class<?>> unknownPropertyConsumer)
      Create a new instance with the given unknownPropertyConsumer.
      Parameters:
      unknownPropertyConsumer - the consumer to be notified whenever unknown properties are encountered
  • Method Details

    • handleUnknownProperty

      public boolean handleUnknownProperty(com.fasterxml.jackson.databind.DeserializationContext ctxt, com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.JsonDeserializer<?> deserializer, Object beanOrClass, String propertyName) throws IOException
      Overrides:
      handleUnknownProperty in class com.fasterxml.jackson.databind.deser.DeserializationProblemHandler
      Throws:
      IOException
    • clearUnexpectedPaths

      public void clearUnexpectedPaths()
      Clear all unexpected path information.
    • getUnexpectedPaths

      public Set<String> getUnexpectedPaths()
      Return the unique unexpected paths in the format className -> propertyName.
      Returns:
      unexpected paths
    • getUnexpectedPropertyPaths

      public Set<String> getUnexpectedPropertyPaths()
      Return the unique unexpected paths in the format className.propertyName.
      Returns:
      unexpected paths
    • getUnknownPropertyCount

      public long getUnknownPropertyCount()
      Current total count of unique unknown properties.
      Returns:
      total count of unique unknown property paths