I want to know if I put a generics method in jax-ws, like:
public List<MyCustomClass> getSomething()
Does the jax-ws support this?
On the client side what will the return of the method looks like?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You will get a List in the client side (or an array of MyCustomClass objects if the WS consumer is written in another language). That won’t be a problem. Remember to always program to interfaces.
Looks like you still don’t have much practice creating WS in Java, so I’ll give you some advices:
You must not send 2 or more objects that contains a circular reference, or you will end with circular reference problems. This is because the JAX-WS tool will create an interminable XML response for the request. It could be very hard to discover. Let’s see a case:
You must always have interfaces in your return classes, not specific Java library classes. This means, your classes should have
List,SetandMap(in case of containers), because this interfaces are in higher level than the implementation classes, and you could get problems if a non-Java client tries to consume your web service method.The classes that will go through your web services should be POJOs (Plain Old Java Objects), not service or business logic layer classes. Why? Because only the attributes values will be marshalled/unmarshalled when communicating with the clients, no method code will appear in the contract of your Web Service.
I’ve faced these three problems in my last SOA project with Java. I hope other people could enhance this answer or provide info with links.