diff --git a/xjx-serdes/src/main/java/io/jonasg/xjx/serdes/XjxSerdes.java b/xjx-serdes/src/main/java/io/jonasg/xjx/serdes/XjxSerdes.java index 3a72642..57b8084 100644 --- a/xjx-serdes/src/main/java/io/jonasg/xjx/serdes/XjxSerdes.java +++ b/xjx-serdes/src/main/java/io/jonasg/xjx/serdes/XjxSerdes.java @@ -12,6 +12,9 @@ import java.util.HashMap; import java.util.Map; +/** + * XjxSerdes provides functionality for serializing and deserializing objects to and from XML. + */ public class XjxSerdes { private final SaxParser saxParser; @@ -23,20 +26,56 @@ private XjxSerdes(SaxParser saxParser, PathWriterIndexFactory pathWriterIndexFac this.pathWriterIndexFactory = pathWriterIndexFactory; } + /** + * Constructs an XjxSerdes instance with default configurations. + */ public XjxSerdes() { this(new SaxParser(), new PathWriterIndexFactory()); } + /** + * Reads XML data and deserializes it into an object of the specified class. + * + * @param data The XML data to read. + * @param clazz The class type to deserialize the XML data into. + * @param The generic type of the class. + * @return The deserialized object. + */ public T read(String data, Class clazz) { return read(new StringReader(data), clazz); } + /** + * Reads XML data from a reader and deserializes it into an object of the specified class. + * + * @param data The reader containing XML data to read. + * @param clazz The class type to deserialize the XML data into. + * @param The generic type of the class. + * @return The deserialized object. + */ public T read(Reader data, Class clazz) { PathBasedSaxHandler saxHandler = new PathBasedSaxHandler<>((rootTag) -> pathWriterIndexFactory.createIndexForType(clazz, rootTag)); saxParser.parse(data, saxHandler); return saxHandler.instance(); } + + /** + * Reads XML data and deserializes it into a map with specified key and value types. + * + * @param data The XML data to read. + * @param mapOf The MapOf instance specifying key and value types. + * @param The type of map keys (only supports String). + * @param The type of map values. + * @return The deserialized map. + * @throws XjxDeserializationException If the map key type is not supported (only supports String). + *

+ * Example usage: + *

{@code
+     * MapOf mapOf = new MapOf() {};
+     * Map deserializedMap = new XjxSerdes().read("...", mapOf);
+     * }
+ */ public Map read(String data, MapOf mapOf) { return read(new StringReader(data), mapOf); }