Class AbstractProblemHandler

java.lang.Object
dev.metaschema.databind.io.AbstractProblemHandler
All Implemented Interfaces:
IProblemHandler
Direct Known Subclasses:
DefaultJsonProblemHandler, DefaultXmlProblemHandler

public abstract class AbstractProblemHandler extends Object implements IProblemHandler
Abstract base class for problem handlers that can validate required fields during deserialization.
  • 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 - true to validate that required fields are present, false to skip validation
  • Method Details

    • isValidateRequiredFields

      protected boolean isValidateRequiredFields()
      Determine if required field validation is enabled.
      Returns:
      true if required fields should be validated, false otherwise
    • handleMissingInstances

      public void handleMissingInstances(IBoundDefinitionModelComplex parentDefinition, IBoundObject targetObject, Collection<? extends IBoundProperty<?>> unhandledInstances) throws IOException
      Description copied from interface: IProblemHandler
      A 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:
      handleMissingInstances in interface IProblemHandler
      Parameters:
      parentDefinition - the bound class on which the missing properties are found
      targetObject - the Java object for the parentDefinition
      unhandledInstances - 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: IProblemHandler
      A 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:
      handleMissingInstances in interface IProblemHandler
      Parameters:
      parentDefinition - the bound class on which the missing properties are found
      targetObject - the Java object for the parentDefinition
      unhandledInstances - the set of instances that had no data to parse
      context - 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 instances
      unhandledInstances - the collection of unhandled instances to validate
      context - 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 provided unhandledInstances.
      Parameters:
      targetObject - the Java object to apply default values to
      unhandledInstances - the collection of unhandled instances to assign default values for
      Throws:
      IOException - if an error occurred while determining the default value for an instance