cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sam.Wang" <BinB.W...@ge.com>
Subject Re: Exception about "*** nor any of its super class is known to this context"
Date Thu, 20 Aug 2009 01:49:49 GMT

Hi dkulp:

Thanks your reply!
I was tried your method, however I get an exception when the response
message be serialized in JAXRSOutInterceptor class. I debug it and find out
the detailed exception info.

javax.ws.rs.WebApplicationException: java.lang.IllegalStateException:
Invalid JSON namespace: http://www.w3.org/2001/XMLSchema-instance

I only added the annotation in CRUDResponse class, just like this:

@XmlRootElement(name = "response")
@XmlSeeAlso( { Apple.class })
public class CRUDResponse <T extends Object> {

Are there others specific reasons in my code?
thanks, Sam.


dkulp wrote:
> 
> 
> Well, the basic reason is that many of the generic types get compiled away
> and 
> thus are not able to be discovered via reflection.   In your case:
> 
> new CRUDResponse<Apple>(apple)
> 
> The "Apple" gets compiled away to just Object.   When we create the 
> JAXBContext, Apple doesn't get added and thus it's now able to write it.  
> The 
> normal way around it is to add @XmlSeeAlso annotations to places JAXB
> would 
> look.   In your case, I THINK if you add an XmlSeeAlso annotation to the 
> CRUDResponse that points at all the objects that it could hold, you should
> be 
> OK.
> 
> Dan
> 
> 
> On Mon August 17 2009 6:11:59 am Sam.Wang wrote:
>> I found this issue today, but I don't understand why?
>>
>> 2009-8-17 18:05:09 org.apache.cxf.jaxrs.provider.AbstractJAXBProvider
>> handleJAXBException
>> Warning: javax.xml.bind.MarshalException
>>  - with linked exception:
>> [javax.xml.bind.JAXBException: class com.demo.Apple nor any of its super
>> class is known to this context.]
>>
>> Following is my demo code:
>>
>> @XmlRootElement(name = "apple")
>> public class Apple {
>>
>> 	private int id = -1;
>> 	private String name;
>> 	private String color;
>> 	private int size;
>>
>>         set...
>>         get...
>> }
>>
>>
>> @XmlRootElement(name = "response")
>> public class CRUDResponse<T extends Object> {
>>
>> 	private int total;
>> 	private int limit;
>> 	private int start;
>> 	private boolean success = true;
>> 	private T entity;
>> 	private List<T> entityList;
>>
>>         set...
>>         get...
>> }
>>
>> 	public Response getApple(String id) throws Exception {
>> 		Apple apple = new AppleServiceImpl().getApple(Integer.parseInt(id));
>> 		return Response.ok(new CRUDResponse<Apple>(apple)).build();
>> 	}
> 
> -- 
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
> 
> 

-- 
View this message in context: http://www.nabble.com/Exception-about-%22***-nor-any-of-its-super-class-is-known-to-this-context%22-tp25004234p25054812.html
Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message