# Interface Mapper<T>

public interface Mapper<T>
Runtime contract a build-time-generated mapper implements for one `@Mapped` class. Application code rarely references `Mapper` directly -- it goes through the typed entry points on `Mappers`. The interface exists so generated code has a single ServiceLoader-friendly shape and so extensions (custom converters, plug-in serializers) can sit on the same type.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `T`
  `fromMap(Map<String, java.lang.Object> map)`
  Inverse of `#toMap`.
  `T`
  `readXml(Element root)`
  Inverse of `#writeXml`.
  `Map<String, java.lang.Object>`
  `toMap(T instance)`
  Serializes `instance` to the JSON map representation that `com.codename1.io.JSONParser` produces in reverse.
  `java.lang.Class<T>`
  `type()`
  The class this mapper handles.
  `void`
  `writeXml(T instance, Element root)`
  Serializes `instance` into the given `Element`.
  `String`
  `xmlRootName()`
  XML root element name (`@XmlRoot.value`, falling back to the class simple name with a lowercase first character).

- ## Method Details

  - ### type

    java.lang.Class<T> type()
    The class this mapper handles. The instance registry on `Mappers` is keyed on this value; generated mappers never call `Class.forName`.

  - ### toMap

    Map<String, java.lang.Object> toMap(T instance)
    Serializes `instance` to the JSON map representation that `com.codename1.io.JSONParser` produces in reverse. Sub-objects that have their own registered `Mapper` are emitted as nested maps; scalars (`String`, boxed primitives, `null`) go in as-is.

  - ### fromMap

    T fromMap(Map<String, java.lang.Object> map)
    Inverse of `#toMap`. Receives a `Map<String, Object>` as produced by `JSONParser` and populates a fresh `T`.

  - ### xmlRootName

    String xmlRootName()
    XML root element name (`@XmlRoot.value`, falling back to the class simple name with a lowercase first character).

  - ### writeXml

    void writeXml(T instance, Element root)
    Serializes `instance` into the given `Element`. Implementations append child elements / attributes; the root element is supplied by the caller so the same mapper can also be invoked from inside a parent element.

  - ### readXml

    T readXml(Element root)
    Inverse of `#writeXml`. Receives an `Element` (the root that `Mappers.toXml` produced or that a parser delivered) and populates a fresh `T`.