JAX-RS - JSON without root node

后端 未结 3 1890
太阳男子
太阳男子 2021-01-12 09:08

I have a restful web service, and the response is:

{
    \"cities\": [{
        \"id\": \"1\",
        \"name\": \"City 01\",
        \"state\": \"A1\"
    }         


        
3条回答
  •  渐次进展
    2021-01-12 09:28

    Good question. I have had an requirement similar to this. I had to have access to the generated raw response and do some manipulation. I achieved that by registering a resonse filter and then adapt a custom reponsewriter. See link below for more details.

    http://www.mentby.com/paul-sandoz/access-to-raw-xml-in-jersey.html
    

    In your response filter, you could clip out the class name from generated json, or better yet, return String in response and use custom json serialization mechanism like Google-gson.

    Let me know if this solution works.

提交回复
热议问题