我想從函數返回JSON,並且拋出一個有關序列化的錯誤。Jax-RS無法返回JSON數據
的錯誤是:
org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.codehaus.jettison.json.JSONArray and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS))
我想我需要做一些系列化,以確保它返回正確的,但我不知道是什麼。
package contentmanagement;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import org.codehaus.jettison.json.JSONArray;
/**
* REST Web Service
*/
@Path("signups")
public class ContentManagement {
@Context
private UriInfo context;
/** Creates a new instance of ContentManagement */
public ContentManagement() {
}
/**
* Retrieves representation of an instance of contentmanagement.ContentManagement
* @return an instance of java.lang.String
*/
@GET @Path("getHtml")
@Produces("application/json")
public JSONArray getHtml() {
JSONArray myData = new JSONArray();
for (int x = 0; x < 12; x++) {
myData.put("This is a test entry"+x);
}
return myData;
}
}
任何人都可以提供洞察哪裏可能會出錯嗎?