Neo4j: post Json array object to extention

When I want to post a json array to extention,  such as

 @Path("/addUsers")
 @POST
 @Produces(MediaType.APPLICATION_JSON)
 @Consumes(MediaType.APPLICATION_JSON)
 public Response addUsers(ArrayList<User> users) throws JSONException { 
    
    //  some codes
 }

 

The errors is

SEVERE: A message body reader for Java class java.util.ArrayList, 
and Java type java.util.ArrayList<com.fadeinfadeout.modle.User>,
 and MIME media type application/json was not found.
The registered message body readers compatible with the MIME media type are:

 

Similar error is

http://stackoverflow.com/questions/7648827/jersey-list-of-json-objects

http://stackoverflow.com/questions/25120513/jersey-json-array-to-list-conversion

http://stackoverflow.com/questions/15593720/jersey-how-to-post-a-list-of-json-objects

http://stackoverflow.com/questions/15593720/jersey-how-to-post-a-list-of-json-objects

 

The solution is to add a wrapper class

package com.fadeinfadeout.modle;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlRootElement;

import org.codehaus.jackson.annotate.JsonAutoDetect;

@XmlRootElement
@JsonAutoDetect
public class Users {
    private List<User> users;

    public Users() {
	this.users = new ArrayList<User>();
    }

    public Users(List<User> users) {
	this.users = users;
    }

    public List<User> getUsers() {
	return users;
    }

    public void setUsers(List<User> users) {
	this.users = users;
    }

}

 

And resource is

    @Path("/addUsers")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response addUsers(Users users) throws JSONException {

     //some codes
}

 

 

 When I want to a generic wrapper class likes

package com.fadeinfadeout.modle;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlRootElement;

import org.codehaus.jackson.annotate.JsonAutoDetect;

@XmlRootElement
@JsonAutoDetect
public class InokEntities<T> {
    private List<T> items;

    public InokEntities() {
	this.items = new ArrayList<T>();
    }

    public InokEntities(List<T> items) {
	this.items = items;
    }

    public List<T> getItems() {
	return items;
    }

    public void setItems(List<T> items) {
	this.items = items;
    }
 
}

 

 But it doesn't work till now. And I can't explain the resons.

 

 

 

 

 

 

你可能感兴趣的:(object)