0

I have a service which returns the List, this object varies depends on different scenario.

Can somebody suggest me does jax-ws support this behaviour or do we have any alternative option.


a is containing a string, instead of a number. string + string returns the concatenation of the two strings - you haven't told Javascript it's a number, so it doesn't treat it like one.

You can use parseFloat and parseInt to turn strings into floating point numbers (have decimal places) or integers (do not). http://www.javascripter.net/faq/convert2.htm

However, be aware that floating point numbers have inaccuracies due to being stored in limited amount of memory - they will round off after a certain number of places (and not decimal places - binary places, for example 0.1 cannot be represented exactly as a floating point number, despite being only one decimal place in base 10!), and if you need to do important financial calculations, you should be aware of this inaccuracy (for example, you might use a fixed point number system instead). Read What Every Computer Scientist Should Know About Floating-Point Arithmetic for more information.

4

1 回答 1

0

由于 JAX-WS 使用 JAXB 来序列化对象,因此 JAXB 需要知道编组或解组的类型名称。在一个独立的环境中可以处理这种事情。但是,在处理对象列表时,这变得更加复杂。

此外,必须在 WSDL 中定义每种数据类型。服务客户端必须能够将响应 XML 转换为所需的数据类型。

如果您希望返回不同类型的不同列表,最简单的方法是对响应使用包装器。例如

public class ResponseWrapper {
    private List<Audio> audios;
    private List<Video> videos;

    // setters and getters
}

@WebService
public class MediaStore {

    @Inject
    AudioService audioService;
    @Inject
    VideoService videoService;

    @WebMethod
    public ResponseWrapper getCollections(String artistId) {
        ResponseWrapper response = new ResponseWrapper();
        response.setAudios(audioService.getAudios(artistId));
        response.setAudios(videoService.getVideos(artistId));
        return response;
    }
}

另一种方法是直接使用SOAP 消息,但您可以避免这样做。

于 2013-05-21T17:18:41.163 回答