简体   繁体   中英

How to return List<String> as Response in JAX-RS

I have read many articles to return List<String> things which I tried are:

1. GenericEntity (getting Internal server error)

2. GSON (getting only string)

Can anyone please help me how to return List<String> as a response in JAX-RS ?

Note: I am using Jersey .

I have tried below code it is working for XML response but not for JSON response

@XmlRootElement(name="List")
public class JAXBList<T> {

    protected List<T> list;

    public JAXBList(){}

    public JAXBList(List<T> list){
        this.list=list;
    }

    @XmlElement(name="Item")
    public List<T> getList(){
        return list;
    }
}

We can use Jackson to get List. I am able to Return List using Jackson. As String is inbuilt Class so doesn't support by jersey to return String. So Explicitly we need to do it from Jackson.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM