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.

Nested types

interface Mapper.DirectOptional: append instance as JSON directly, without building a map first.

Methods

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

Method details

type

public abstract 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

public abstract Map<String, 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

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

xmlRootName

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

writeXml

public abstract 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

public abstract 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.