Interface Converter<P,M>

Type Parameters:
P - the presentation type (e.g., String)
M - the model type (e.g., Integer, Date, BigDecimal)
All Known Implementing Classes:
StringToBigDecimalConverter, StringToBooleanConverter, StringToDateConverter, StringToDoubleConverter, StringToEnumConverter, StringToIntegerConverter, StringToLocalDateConverter, StringToLocalDateTimeConverter, StringToLongConverter

public interface Converter<P,M>
Bidirectional converter between a presentation type and a model type.

Converters translate values between their UI representation (typically String) and the Java type used in the domain model. For example, a Converter<String, Integer> converts the text "42" to the integer 42 and vice versa.

Usage:


 Converter<String, Integer> converter = new StringToIntegerConverter("Not a number");
 Integer value = converter.convertToModel("42");       // returns 42
 String text = converter.convertToPresentation(42);     // returns "42"
 
Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Converts a presentation value to its model representation.
    Converts a model value to its presentation representation.
  • Method Details

    • convertToModel

      M convertToModel(P value) throws ConversionException
      Converts a presentation value to its model representation.
      Parameters:
      value - the presentation value to convert (may be null)
      Returns:
      the model value
      Throws:
      ConversionException - if conversion fails
    • convertToPresentation

      P convertToPresentation(M value)
      Converts a model value to its presentation representation.
      Parameters:
      value - the model value to convert (may be null)
      Returns:
      the presentation value