jdemic wrote:
> Hey All,
>
> I'm attempting to use XmlAdapter to adapt some classes from framework
> classes that do not have default noarg constructors. the code looks like
> this:
>
> protected String marshal(RemoteInvocationResult result) {
> String xml;
> try {
> StringWriter writer = new StringWriter();
> javax.xml.bind.Marshaller m = context.createMarshaller();
> m.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT,
> Boolean.TRUE);
> m.marshal(new JAXBElement(new QName("uri","local"),
> RemoteInvocationResult.class, result),writer);
> xml = writer.toString();
> } catch (JAXBException ex) {
> System.out.println();
> throw(new XmlException("Could not map " + result, ex));
> }
> return xml;
> }
>
> I wrote an XmlTypeAdapter for RemoteInvocationResult. I'm not sure how to
> use the @XmlJavaTypeAdapter annotation to get the adapter to kick in. ive
> attempted annotating the class as well as the above method to no avail.
> I've also tried setting up the adapter in a package-info.java file. the
> documentation ive looked at seems to assume one has access to the source of
> the annotated object. this isnt the case with the above...
Adapting class when you can't modify its source code still remains to be
a challenge.
In the above case, the correct answer is actually for you to manually
invoke the adapter before calling the marshaller :-O
I know, I know...
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com