You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Maleldil <ge...@gmail.com> on 2008/10/27 20:22:05 UTC

Problem serializing complex data type

I'm having this issue when attempting to serialize an object that exists
within another object (complex data type).  Here are my classes:

The containing class:

@XmlRootElement(name = "result")
@XmlAccessorType(XmlAccessType.NONE)
@XmlSeeAlso({TripVO.class}
public class ResultVO {	
	@XmlElement
	private String id;
	@XmlElement
	private boolean success;
	@XmlElement
	private String[] messages;
	@XmlElement
	private Object data;
}

The data element is the one which is having issues.  In my test case, the
data element is an instance of the following class:

@XmlRootElement(name = "trip")
@XmlAccessorType(XmlAccessType.NONE)
public class TripVO {
	
	// Set by the client service
	@XmlElement
	private String id;
	@XmlElement
	private String name;
	@XmlElement
	private String tripType;
	@XmlElement
	private String userName;
	@XmlElement
	private int rank;
	
	private ArrayList<String> tags;
	
	private String desc;
	private String imageUrl;
	private String startAddress;	
	
	private int duration;
	
	@XmlElement
	private String startDate;
	
	private List<TripPointVO> points;
	

	public TripVO() {}
}

When I attempt to serialize ResultVO I get the exception: 

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

If I leave out the @XmlSeeAlso annotation, I get:

javax.xml.bind.JAXBException: class com.randmcnally.trip.common.vo.TripVO
nor any of its super class is known to this context.

I am not using any explicitly defined namespaces, as this is a solely
JSON-based REST interface.  I want the ResultVO class to act as an envelope
for my other classes (i.e. every response will have its attributes, along
with a sub-object called data with the specific information).  Does anyone
have any idea how I can fix this?
-- 
View this message in context: http://www.nabble.com/Problem-serializing-complex-data-type-tp20194531p20194531.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Problem serializing complex data type

Posted by Joe Sunday <su...@csh.rit.edu>.
It seems to work ok for me.

--Joe

On Oct 27, 2008, at 5:21 PM, Maleldil wrote:

>
> Is it possible to map to a blank prefix?  For example, say I use the
> namespace "com.example.json" but I don't want any prefixes in my JSON
> objects, can I do something like the following (using JAX-RS and  
> Spring,
> btw):
>
> <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
>    <entry key="com.example.json" value=""/>
>    <entry key="http://cxf.apache.org/bindings/xformat" value="cxf"/>
> </util:map>
>
>
>
> dkulp wrote:
>>
>>
>> I think you just need to add a namespace mapping for that namespace  
>> into
>> the
>> MappedXMLOutputFactory for jettison.   Wherever you create your  
>> output
>> factory, just map that namespace.
>>
>> Dan
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Problem-serializing-complex-data-type-tp20194531p20196682.html
> Sent from the cxf-user mailing list archive at Nabble.com.


Re: Problem serializing complex data type

Posted by Maleldil <ge...@gmail.com>.
Is it possible to map to a blank prefix?  For example, say I use the
namespace "com.example.json" but I don't want any prefixes in my JSON
objects, can I do something like the following (using JAX-RS and Spring,
btw):

<util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
    <entry key="com.example.json" value=""/>
    <entry key="http://cxf.apache.org/bindings/xformat" value="cxf"/>
</util:map>



dkulp wrote:
> 
> 
> I think you just need to add a namespace mapping for that namespace into
> the 
> MappedXMLOutputFactory for jettison.   Wherever you create your output 
> factory, just map that namespace.
> 
> Dan
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-serializing-complex-data-type-tp20194531p20196682.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Problem serializing complex data type

Posted by Daniel Kulp <dk...@apache.org>.
I think you just need to add a namespace mapping for that namespace into the 
MappedXMLOutputFactory for jettison.   Wherever you create your output 
factory, just map that namespace.

Dan


On Monday 27 October 2008 3:22:05 pm Maleldil wrote:
> I'm having this issue when attempting to serialize an object that exists
> within another object (complex data type).  Here are my classes:
>
> The containing class:
>
> @XmlRootElement(name = "result")
> @XmlAccessorType(XmlAccessType.NONE)
> @XmlSeeAlso({TripVO.class}
> public class ResultVO {
> 	@XmlElement
> 	private String id;
> 	@XmlElement
> 	private boolean success;
> 	@XmlElement
> 	private String[] messages;
> 	@XmlElement
> 	private Object data;
> }
>
> The data element is the one which is having issues.  In my test case, the
> data element is an instance of the following class:
>
> @XmlRootElement(name = "trip")
> @XmlAccessorType(XmlAccessType.NONE)
> public class TripVO {
>
> 	// Set by the client service
> 	@XmlElement
> 	private String id;
> 	@XmlElement
> 	private String name;
> 	@XmlElement
> 	private String tripType;
> 	@XmlElement
> 	private String userName;
> 	@XmlElement
> 	private int rank;
>
> 	private ArrayList<String> tags;
>
> 	private String desc;
> 	private String imageUrl;
> 	private String startAddress;
>
> 	private int duration;
>
> 	@XmlElement
> 	private String startDate;
>
> 	private List<TripPointVO> points;
>
>
> 	public TripVO() {}
> }
>
> When I attempt to serialize ResultVO I get the exception:
>
> java.lang.IllegalStateException: Invalid JSON namespace:
> http://www.w3.org/2001/XMLSchema-instance
>
> If I leave out the @XmlSeeAlso annotation, I get:
>
> javax.xml.bind.JAXBException: class com.randmcnally.trip.common.vo.TripVO
> nor any of its super class is known to this context.
>
> I am not using any explicitly defined namespaces, as this is a solely
> JSON-based REST interface.  I want the ResultVO class to act as an envelope
> for my other classes (i.e. every response will have its attributes, along
> with a sub-object called data with the specific information).  Does anyone
> have any idea how I can fix this?



-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog