users@jersey.java.net

Automatically converting model objects to JaxbElements / "Wrapping" providers

From: Johannes Schneider <mailings_at_cedarsoft.com>
Date: Tue, 08 Jun 2010 17:45:34 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi guys,

at the moment I am struggling with the conversion of my model to XML.
While I prefer JAXB over other solutions (especially because I can add
JSON support easily), I don't want to pollute my model with JAXB
annotations and default constructors.
So I am trying to create some sort of special JAXB model that is just a
simple representation of my model especially made for the JAXB
conversion. (This will also allow me to add URIs to the XML easily).

Now I'd like to make the conversion from my model to the JAXB model
happen automatically. Therefore I thought I could try a MessageBodyWriter.
But of course I want to use the existing JAXB magic, too. But the
BodyWriters cannot be wrapped easily/automatically.

So can anybody give me a hint what direction I could take?



To make it clear, here a small example:

Model:
        - User

JAXB-Model (easily created from User using my own User2JaxbBridge):
        - JaxbUser (annotated with XmlRootElement)


My Resource is returning a User that shall be automatically converted to
a JaxbUser (using my bridge) and then automatically to XML using the
existing JAXB stuff in Jersey...



Thanks,

Johannes
- --
Johannes Schneider - blog.cedarsoft.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBAgAGBQJMDmWbAAoJEAytD9R7Qv6dH+QIAJi2IeJPZwOIWQyCX2wKj3zO
xofM3mKYuHcytACvodJUANeOi//GBGn0Lm9lIWIcQkxWX27xJGJ89JDBmPpsLqDc
XUPn7xdgFLJynFlnl/kr1NJmTOF7y6UC0StoWPnY3bfanWoLZcpdiy3PS5BItVdx
Ad7g11etW+Im3jGL5t1COSl/5smsdSATVdQKTMXSib5Qc4b/poTTuq7WKUDISJ94
bmsc78F9NjRPOZmmMCSh64iMdAiPUBKdJT9p/m0uF5od3WGsbNPDByre6/P4QDV2
MnGOMOl0c9yTpg7Jj3nSBH+lE6VZAX5uQ+2o7BSh2wzKmXfPSDWH8qLsXa8dWAo=
=0mrX
-----END PGP SIGNATURE-----