Re: [Simple-support] Beginner Questions
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2007-06-19 07:44:08
|
Hi,
With regard to the @Root annotation it is currently an optional annotation. What it does is tell the serialization process what the root element name of the object should be. For example take the following objects:
@
public class First {
}
public class Second extends First {
}
@Root
public class Third extends Second {
}
If I serialize these objects the following is created:
1) new First()
<first/>
2) new Second()
<first/>
3) new Third()
<third/>
So here the @Root annotation tells the persistence engine what the root element will be. Also, it is used to specify overrides if required:
@Root(name="myRoot")
public class SomeLongNameNotToBeUsedAsAnElementName {
}
This results in:
<myRoot/>
Finally, you can specify the parsing mode for the object using the strict attribute:
@Root(name="myName", strict=true)
public class LooseMatchObject {
}
This allows the object to match only certain parts of the XML document, meaning that you do not need to write a complete object representation of the XML.
With regard to the requirement for an annotation on serializable fields and methods this was taken because I believe for all but the most trivial of objects, you are going to need to specify meta data. For example an @Element annotation may be optional, or require CDATA externalization, I think it would be more confusing to see an object with @Element and @Attribute annotations on some fields and nothing on others, it is not immediately obvious to the reader of your code what the external representation of your object is.
Also, I feel that the @ElementList is one of the most common annotations used, the @Element annotation serializes in a different manner, again I feel that seeing an object with a mixture of annotated and unannotated fields would make the XML schema of the class less obvious.
Although I can fully appreciate your comments, it is obviously an attractive option to have your POJOs serializable without modification, I feel annotations are nessecary. One of the primary goals of this project from the outset is that there was a single entity representing everything, the annotated object represents the XML schema. So there are no external mapping files to maintain and refactor, no mapping classes etc. Just a single object and a single point of refactoring, I have found that this helped me develop quickly.
Thanks for the feedback, any suggestions on how the framework could be modified/improved are appreciated.
Niall
----- Original Message ----
From: Travis Reeder <tr...@gm...>
To: sim...@li...
Sent: Tuesday, June 19, 2007 7:35:01 AM
Subject: [Simple-support] Beginner Questions
Hi,
I just came across your project and it looks very interesting indeed. A few questions/comments:
- Why is the @Root required? It looks like you have to always use it which means that it's not really useful. Unless I'm missing something.
- I also noticed that if you don't use the @Attribute or @Element, then the field is not serialized. It would be a lot more user friendly to include all fields, probably defaulting to @Element, and the use the annotations to exclude the ones you don't want with something similar to JPA's @Transient or change the way it's serialized with @Attribute.
I have to admit that as soon as I saw that you must have all these annotations, my interest decreased. It seems to me the default could work out of the box with no annotations like XStream and you only add annotations to modify that default behaviour. Rather than the current behaviour of doing nothing unless you add annotations.
Just my 2 cents.
Travis
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html |