Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Daniele Futtorovic Newsgroups: comp.lang.java.programmer Subject: Re: JAXB Object (not strongly typed) within class creating MarshalException Date: Fri, 19 Apr 2013 20:37:41 +0200 Organization: A noiseless patient Spider Lines: 26 Message-ID: References: <0cda468a-d4f2-47bb-a834-1bca6e1d525e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 19 Apr 2013 18:34:50 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="437fcb7d98cca7e7aabbd8fee47fe4ae"; logging-data="7464"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1Afgd1a4ESF8OfsuE9Q4y" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 In-Reply-To: <0cda468a-d4f2-47bb-a834-1bca6e1d525e@googlegroups.com> Cancel-Lock: sha1:7PbTttupcEBXkIfa3WadvztoPqE= Xref: csiph.com comp.lang.java.programmer:23513 On 16/04/2013 17:22, Greg allegedly wrote: > I have a colleague that is trying to get JAXB to create XML and then > create the class back again where one of the member variables will > just be an Object. That is, it will not be strongly typed and it > will contain a myriad of different types depending on what the XML > coming in contains. However, a simple example results in a > MarshalException with linked exception: JAXBException: class (any > class here) nor any of its super class is known to this context. How > can this be solved? I don't think it can be solved like this. How is the unmarshaller supposed to know what to unmarshal the data to? But more importantly, what's that data (the XML you created) gonna be used for? Some(one|thing) has to understand it, right? But if for some(one|thing) to understand it, it's oughta have a well-defined structure, ought it not? It's oughta have a schema, ought it not? Well, then bloody formalise and code that schema, and then if you want to have your JAXB context be aware of classes the use of which it cannot infer, use @XmlSeeAlso. -- DF.