Package org.kiwiproject.json
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
ConstructorsConstructorDescriptionCreate a new instance with a no-opunknownPropertyConsumer.LoggingDeserializationProblemHandler(BiConsumer<String, Class<?>> unknownPropertyConsumer) Create a new instance with the givenunknownPropertyConsumer. -
Method Summary
Modifier and TypeMethodDescriptionvoidClear all unexpected path information.Return the unique unexpected paths in the formatclassName -> propertyName.Return the unique unexpected paths in the formatclassName.propertyName.longCurrent total count of unique unknown properties.booleanhandleUnknownProperty(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
-
Constructor Details
-
LoggingDeserializationProblemHandler
public LoggingDeserializationProblemHandler()Create a new instance with a no-opunknownPropertyConsumer. -
LoggingDeserializationProblemHandler
Create a new instance with the givenunknownPropertyConsumer.- 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:
handleUnknownPropertyin classcom.fasterxml.jackson.databind.deser.DeserializationProblemHandler- Throws:
IOException
-
clearUnexpectedPaths
public void clearUnexpectedPaths()Clear all unexpected path information. -
getUnexpectedPaths
Return the unique unexpected paths in the formatclassName -> propertyName.- Returns:
- unexpected paths
-
getUnexpectedPropertyPaths
Return the unique unexpected paths in the formatclassName.propertyName.- Returns:
- unexpected paths
-
getUnknownPropertyCount
public long getUnknownPropertyCount()Current total count of unique unknown properties.- Returns:
- total count of unique unknown property paths
-