JAX-RS - JSON without root node

后端 未结 3 1884
太阳男子
太阳男子 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:52

    Answer from Kim Burgaard above works also for Jersey Spring WS. I had the same problem using Glassfish 3.0 and solved it adding the parameter shown below.

    Example web.xml

    
    
        
            contextConfigLocation
            classpath:applicationContext.xml
        
        
            org.springframework.web.context.ContextLoaderListener
        
        
            org.springframework.web.context.request.RequestContextListener
        
        
            Jersey Spring Web Application
            com.sun.jersey.spi.spring.container.servlet.SpringServlet
            
                com.sun.jersey.config.property.packages
                org.codehaus.jackson.jaxrs
    
            
        
        
            Jersey Spring Web Application
            /services/*
        
    
    

    Example applicationContext.xml

    
    
        
        
    
    

提交回复
热议问题