JSON output of a JAX-WS webservice?

后端 未结 2 1702
抹茶落季
抹茶落季 2020-12-18 09:30

Is it possible that a jax-ws soap-webservice can output json format instead of xml?

@Component
@WebServic         


        
2条回答
  •  独厮守ぢ
    2020-12-18 10:01

    Apparently it's possible by following the instructions indicated at https://jax-ws-commons.java.net/json/

    Summing up:

    @BindingType(JSONBindingID.JSON_BINDING)
    public class MyService {
    
        public Book get(@WebParam(name="id") int id) {
            Book b = new Book();
            b.id = id;
            return b;
        }
    
        public static final class Book {
            public int id = 1;
            public String title = "Java";
        }
    }
    

    You just need jaxws-json.jar in your WEB-INF/lib for this to work.

    I hope it helps!

提交回复
热议问题