users@jersey.java.net

[Jersey] Can I unmarshall JSON without knowing which class to use?

From: <neilahart_at_gmail.com>
Date: Fri, 16 Dec 2011 18:18:16 +0000 (GMT)

I have two methods that handle the different XML and JSON submissions
to our server. When using the json, I need to pass in the class while
JAXB handles figuring out which class. Is there a way to pass in the
class as part of the json submission?

        protected Object unmarshallBeanXML (InputStream istrm)
                        throws Exception
        {
                Unmarshaller umarsh = jc.createUnmarshaller ();
                return xmlcommand = umarsh.unmarshal (istrm);
        }

        protected Object unmarshallBeanJson (InputStream istrm, Class
clazz)
                        throws Exception
        {
                JSONUnmarshaller umarsh =
((JSONJAXBContext)jc).getJSONUnmarshaller(jc.createUnmarshaller ());
                return umarsh.unmarshalFromJSON (istrm, clazz);
        }

example jaxb class.

@XmlRootElement(name = "login")
public class Login {
}