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.DeserializationProblemHandlerA JacksonDeserializationProblemHandlerthat logs and keeps track of unknown properties during JSON deserialization. Any unexpected/unknown properties are logged as warnings and stored in-memory in aConcurrentMap.Optionally, you can supply a
BiConsumerto 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 Summary
Constructors Constructor Description LoggingDeserializationProblemHandler()Create a new instance with a no-opunknownPropertyConsumer.LoggingDeserializationProblemHandler(BiConsumer<String,Class<?>> unknownPropertyConsumer)Create a new instance with the givenunknownPropertyConsumer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearUnexpectedPaths()Clear all unexpected path information.Set<String>getUnexpectedPaths()Return the unique unexpected paths in the formatclassName -> propertyName.Set<String>getUnexpectedPropertyPaths()Return the unique unexpected paths in the formatclassName.propertyName.longgetUnknownPropertyCount()Current 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 Detail
-
LoggingDeserializationProblemHandler
public LoggingDeserializationProblemHandler()
Create a new instance with a no-opunknownPropertyConsumer.
-
LoggingDeserializationProblemHandler
public LoggingDeserializationProblemHandler(BiConsumer<String,Class<?>> unknownPropertyConsumer)
Create a new instance with the givenunknownPropertyConsumer.- 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:
handleUnknownPropertyin classcom.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 formatclassName -> propertyName.- Returns:
- unexpected paths
-
getUnexpectedPropertyPaths
public Set<String> 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
-
-