What is the cost of using the annotations? For Instance, if I have my POJO’s and use them as input/output for web service calls but then make the EJB accessible only through RMI, how does this effect performance? Is there still overheard with the annotations on the POJO, or should the annotations be removed. The annotations are nice to have because we can easily unmarshal our response and view it in a nice format, but I’m not sure what the overhead is for our production environment where we are obtaining ~100k calls per hour.
Annotations are only used by tools to do some something with a class. Annotations doesn’t add overhead per se, it is what the tool will do with the annotations that will add overhead. The only reasonable way to measure if they will add any overhead that is problematic in your situation is of course to test with and without the annotations.
Implement the same functionality using annotated classes and run a suit of tests that simulates say 5 hours worth of traffic. The do the same without the annotated solution and test the with same load. Is the difference significant? Use the solution that is best both from a performance perspective and a maintenance perspective.
[…] to the onedb engine. This is often not possible for legacy classes or conflicts with building ‘pure’ POJO objects. The onedb engine therefore allows defining nodes in the onedb cloud, which do not […]
i am developing a RESTful service which reads data from oracle database, and populates POJO using a framework like hibernate, and then POJO are converted to XML which will be the output from REST application which can be viewed using a browser by typing in a REST request URL. I was exploring other methods for POJO to XML conversion. it also works in a similar method to the JAXB library you have explained above. POJO are annotated with @xstreamAlias for xmlElement , @xstreamAsAttribute for xmlAttribute , and then the xstream API on the POJO will serialize them to xml output visible on the browser.
i am still checking out where the hook or the web application configuration is specified so that the POJO is operated upon the configured xstream API’s.
to my knowledge i am aware that the output from the Controller is a org.springframework.web.servlet.ModelAndView object which wraps the POJO which has to be serialized. hope i am making sense here.
i also believe we can also add custom converters by extending com.thoughtworks.xstream.converters.Converter and overriding 2 methods – boolean canConvert(Class classType) and void marshal(Object value, com.thoughtworks.xstream.io.HierarchicalStreamWriter writer, com.thoughtworks.xstream.converters.MarshallingContext context) to add custom xml serialization.
also i think there is some integration between spring framework, and xstream, and finding many spring MVC applications using xstream. for example any class extending the org.springframework.web.servlet.view.xml.MarshallingView can use the org.springframework.oxm.xstream.XStreamMarshaller as it marshaller..
let me know if you discover any more information regarding the same..
i have 2 queries related to the context/subject of this thread
– what changes would be needed to write the POJO object to an output stream of a socket, or a servlet output stream , or just to write it directly to a file. in my case i would want the objects to be written to the output stream of the HttpServletResponse object.
– what does @XmlAnyElement annotation inform the tool which is marshalling the object into xml. does it mean it is a collection or list object, and the tool has to iterate over the objects in the list, and invoke the marshaller on each of the list object ?
the other thing i wanted to know is how to add formatting to the output xml. the string xml is printed out in one line. but i would want the output xml to be formatted and indented according to the hierarchy of the data.
Did you ever think about fetching and reusing the JaxbContext for the objects, which must already exist in the Jersey framework if a call came from the client as a string and then got converted to a POJO … for those of us who want to do something like get a json-string message and then proxy it forward to another webservice as a xml-string message … it would be very cool to not have to create additional jaxbcontext objects for the conversion … thoughts?