[Simple-support] Support for almost-primitive types, Converters in attributes and Arrays in attribu
Brought to you by:
niallg
|
From: Raphael J. <rap...@gm...> - 2011-05-19 13:10:25
|
Hello there, I am using the Simple XML framework extensively for all my XML parsing / generating tasks and I am very happy with it. However, I would like to propose some enhancements that would enable me to serialize / deserialize almost all my classes without the need of further work, except for some annotations. = Almost-primitive types First, I would like to ask for the support of "almost-primitive" types. In the Jersey REST Servlet (based on JAX-RS API), there is a convention that states : Any class providing a "public Constructor(String)" or a static method "static public fromString(String)" can be considered as a native type and is parsed, serialized without having to write a custom Converter / Mapper. The toString() method is using for serialization. This is very handy, as writing a single static method for a class is less work than writing a Converter and having to register it, or to annotate every occurrence of attributes of its type. = Only primitive types supported for attributes ? Also, I have experienced that custom converters (either registered in a strategy, or specified as annotations with the AnnotationStrategy) are not supported for attributes. It seems that attributes explicitly require the use of Java primitive types. Therefore, I had to write custom getters / setters with Strings to overcome this limitation. = Unique annotation to parse Lists and Arrays, and new annotation to parse arrays of attributes (with a separator) I think that the distinction between ElementArray and ElementList is not necessary, as it is semantically the same structure of objects ( a sequence of objects) : The framework should handle transparently Arrays and List without having to specify it in the annotation. let's have a unique "ElementSequence" annotation. Also, this is a very common situation to have several values wrapped into a unique attributes, as comma separated values. <task times="2 s, 3 h, 4m" > I would like to be able to write something like AttributeSequence(name="times", separator=",") Duration[] durations; Duration being a class that provides a static "fromString(String)" method, to parse Strings. With that, the framework should be able to serialize / parse this code without the need of any other information / code. What do you think about those requests ? Some of them may be already supported : Please tell me if I missed something. Thanks again for your great work, Best regards, Raphael JOLIVET |