Class Contract

java.lang.Object
org.apache.camel.spi.Contract

public class Contract extends Object
Declares the expected input and/or output DataType of an Endpoint or Processor.

When a route step declares a contract, Camel compares the message's actual DataType against the declared input and output types and, if they differ, applies a matching Transformer to convert the payload; it can also run a Validator when isValidateInput() or isValidateOutput() is set. This is the mechanism behind declarative input/output typing on routes.

See Transformer in the Camel user manual.

See Also:
  • Constructor Details

    • Contract

      public Contract()
  • Method Details

    • getInputType

      public @Nullable DataType getInputType()
      Gets the declared input data type.
      Returns:
      the input type, or null if none is declared
    • setInputType

      public void setInputType(String inputType)
      Set the input data type.
      Parameters:
      inputType - input data type
    • setInputType

      public void setInputType(Class<?> clazz)
      Set the input data type with Java class.
      Parameters:
      clazz - Java class which represents input data type
    • getOutputType

      public @Nullable DataType getOutputType()
      Gets the declared output data type.
      Returns:
      the output type, or null if none is declared
    • setOutputType

      public void setOutputType(String outputType)
      Set the output data type.
      Parameters:
      outputType - output data type
    • setOutputType

      public void setOutputType(Class<?> clazz)
      Set the output data type with Java class.
      Parameters:
      clazz - Java class which represents output data type
    • isValidateInput

      public boolean isValidateInput()
      Whether the input should be validated against the input data type.
      Returns:
      true if input validation is enabled
    • setValidateInput

      public void setValidateInput(boolean validate)
      Whether to validate the input
    • isValidateOutput

      public boolean isValidateOutput()
      Whether the output should be validated against the output data type.
      Returns:
      true if output validation is enabled
    • setValidateOutput

      public void setValidateOutput(boolean validate)
      Whether to validate the output
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isEmpty

      public boolean isEmpty()
    • equals

      public boolean equals(@Nullable Object target)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object