# convert abstract method

T convert(

1. S source

)

A generic interface for converting an input of type `S` into an output of type `T`.

Converters are commonly used in Jetleaf when transforming data between different layers, formats, or domains. This abstraction allows developers to define reusable transformation logic while keeping code strongly typed.

- `S` is the source type (input).
- `T` is the target type (output).

## Example

Converting a `String` to an `int`:

    class StringToIntConverter implements Converter<String, int> {
      @override
      int convert(String source) {
        return int.parse(source);
      }
    }

    void main() {
      final converter = StringToIntConverter();
      final number = converter.convert("42");
      print(number); // 42
    }

Converting a `Map` into a custom model:

    class User {
      final String name;
      final int age;
      User(this.name, this.age);
    }

    class MapToUserConverter implements Converter<Map<String, Object?>, User> {
      @override
      User convert(Map<String, Object?> source) {
        return User(source['name'] as String, source['age'] as int);
      }
    }

    void main() {
      final converter = MapToUserConverter();
      final user = converter.convert({'name': 'Alice', 'age': 30});
      print(user.name); // Alice
    }

## Implementation

    T convert(S source);