Jersey, how to POST a list of JSON objects?

前端 未结 5 1432
栀梦
栀梦 2021-02-05 22:25

I am building a RESTful web-service in Java using Jersey 1.11, and have problems implementing a method which consumes a list of JSON-ised entities. The single instance method wo

5条回答
  •  甜味超标
    2021-02-05 22:54

    Ok, so in the end I solved this using a simple wrapper class in order to generate { items : [{ }, { }, ... ]}. I guess there is a way to have a generic wrapper but for now this will do:

    @XmlRootElement
    public class MyEntityWrapper implements Serializable {
    
        private static final long serialVersionUID = 1L;
    
        private List items;
    
        public MyEntityWrapper() {
            this.items = new ArrayList();
        }
    
        public MyEntityWrapper(List items) {
            this.items = items;
        }
    
        public List getItems() {
            return items;
        }
    
        public void setItems(List items) {
            this.items = items;
        }
    }
    

提交回复
热议问题