java.lang.Object
dev.metaschema.databind.io.AbstractProblemHandler
- All Implemented Interfaces:
IProblemHandler
- Direct Known Subclasses:
DefaultJsonProblemHandler,DefaultXmlProblemHandler
Abstract base class for problem handlers that can validate required fields
during deserialization.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstruct a new problem handler with default settings.protectedAbstractProblemHandler(boolean validateRequiredFields) Construct a new problem handler with the specified validation setting. -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidapplyDefaults(Object targetObject, Collection<? extends IBoundProperty<?>> unhandledInstances) A utility method for applying default values for the providedunhandledInstances.voidhandleMissingInstances(IBoundDefinitionModelComplex parentDefinition, IBoundObject targetObject, Collection<? extends IBoundProperty<?>> unhandledInstances) A callback used to handle bound properties for which no data was found when the content was parsed.voidhandleMissingInstances(IBoundDefinitionModelComplex parentDefinition, IBoundObject targetObject, Collection<? extends IBoundProperty<?>> unhandledInstances, ValidationContext context) A callback used to handle bound properties for which no data was found when the content was parsed, with additional validation context.protected booleanDetermine if required field validation is enabled.protected voidvalidateRequiredFields(IBoundDefinitionModelComplex parentDefinition, Collection<? extends IBoundProperty<?>> unhandledInstances, ValidationContext context) Validate that all required fields have values or defaults.
-
Constructor Details
-
AbstractProblemHandler
protected AbstractProblemHandler()Construct a new problem handler with default settings.Required field validation is enabled by default.
-
AbstractProblemHandler
protected AbstractProblemHandler(boolean validateRequiredFields) Construct a new problem handler with the specified validation setting.- Parameters:
validateRequiredFields-trueto validate that required fields are present,falseto skip validation
-
-
Method Details
-
isValidateRequiredFields
protected boolean isValidateRequiredFields()Determine if required field validation is enabled.- Returns:
trueif required fields should be validated,falseotherwise
-
handleMissingInstances
public void handleMissingInstances(IBoundDefinitionModelComplex parentDefinition, IBoundObject targetObject, Collection<? extends IBoundProperty<?>> unhandledInstances) throws IOException Description copied from interface:IProblemHandlerA callback used to handle bound properties for which no data was found when the content was parsed.This can be used to supply default or prescribed values based on application logic.
- Specified by:
handleMissingInstancesin interfaceIProblemHandler- Parameters:
parentDefinition- the bound class on which the missing properties are foundtargetObject- the Java object for theparentDefinitionunhandledInstances- the set of instances that had no data to parse- Throws:
IOException- if an error occurred while handling the missing instances
-
handleMissingInstances
public void handleMissingInstances(IBoundDefinitionModelComplex parentDefinition, IBoundObject targetObject, Collection<? extends IBoundProperty<?>> unhandledInstances, @Nullable ValidationContext context) throws IOException Description copied from interface:IProblemHandlerA callback used to handle bound properties for which no data was found when the content was parsed, with additional validation context.This method provides richer context information for error messages including source location, document path, and format-specific details.
The default implementation delegates to
IProblemHandler.handleMissingInstances(IBoundDefinitionModelComplex, IBoundObject, Collection)for backward compatibility.- Specified by:
handleMissingInstancesin interfaceIProblemHandler- Parameters:
parentDefinition- the bound class on which the missing properties are foundtargetObject- the Java object for theparentDefinitionunhandledInstances- the set of instances that had no data to parsecontext- the validation context with location and path information, may be null for backward compatibility- Throws:
IOException- if an error occurred while handling the missing instances
-
validateRequiredFields
protected void validateRequiredFields(@NonNull IBoundDefinitionModelComplex parentDefinition, @NonNull Collection<? extends IBoundProperty<?>> unhandledInstances, @Nullable ValidationContext context) throws IOException Validate that all required fields have values or defaults.This method handles choice groups correctly: if an instance belongs to a choice and at least one sibling in that choice was provided, the instance is not considered missing.
- Parameters:
parentDefinition- the definition containing the unhandled instancesunhandledInstances- the collection of unhandled instances to validatecontext- the validation context with location and path information, may be null- Throws:
IOException- if a required field is missing and has no default value
-
applyDefaults
protected static void applyDefaults(@NonNull Object targetObject, @NonNull Collection<? extends IBoundProperty<?>> unhandledInstances) throws IOException A utility method for applying default values for the providedunhandledInstances.- Parameters:
targetObject- the Java object to apply default values tounhandledInstances- the collection of unhandled instances to assign default values for- Throws:
IOException- if an error occurred while determining the default value for an instance
-