cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthony1975 <anthony.denech...@gmail.com>
Subject Re: WADL Json Error
Date Thu, 28 Aug 2014 09:41:31 GMT
So, i follow your instructions..If you can tell me where I'm wrong :)
I put your comments (bold) in the code.

import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import javax.inject.Inject;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import org.w3c.dom.Document;

import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;

@Provider
@Produces({ MediaType.APPLICATION_JSON, "text/json" })
public class WadlJacksonJsonProvider
    implements MessageBodyWriter {
  
	private final JacksonJaxbJsonProvider jsonProvider; 
	
*        //  init JacksonJaxbProvider*
	@Inject 
	 public WadlJacksonJsonProvider(JacksonJaxbJsonProvider jsonProvider) { 
		this.jsonProvider = jsonProvider; 
	} 
	
*        //make sure getSize() returns -1*	
       @Override
	public long getSize(Object arg0, Class<?> arg1, Type arg2,
			Annotation[] arg3, MediaType arg4) {
		// Return -1 to indicate that no explicit 
	    // content lenght can be assigned 
		return -1;
	}

	 @Override
	  public boolean isWriteable(Class<?> type, Type genericType,
	      Annotation[] annotations, MediaType mediaType) {
*                 // check if it is DOM Document, if yes, return false*
		 if (Document.class.isAssignableFrom(type)) {
			 return false;
		 } else {
*                          // otherwise delegate to
JacksonJaxbProvider.isWriteable *
			 return jsonProvider.isWriteable(type, genericType, annotations,
mediaType);
		 }
	  }

	@Override
	public void writeTo(Object arg0, Class<?> arg1, Type arg2,
			Annotation[] arg3, MediaType arg4,
			MultivaluedMap<String, Object> arg5, OutputStream arg6)
			throws IOException, WebApplicationException {
		// TODO Auto-generated method stub
		
	}
}

Perhaps, it's my injection in config file...I call 	
<bean id="jsonProvider"
class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider"/>
<bean id="wadlJacksonJsonProvider"
class="fr.scc.utils.WadlJacksonJsonProvider"/>

Thanks

Anthony



--
View this message in context: http://cxf.547215.n5.nabble.com/WADL-Json-Error-tp5744477p5748246.html
Sent from the cxf-user mailing list archive at Nabble.com.

Mime
View raw message