Class 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.
    • Constructor Detail

      • 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 Detail

      • 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