Saturday, January 18, 2014

How to send an array of objects using Soap UI


Let me show you an example and maybe it can help you.

    package mypackage;

    import java.io.Serializable;
    import java.util.Date;

    public class Thing implements Serializable{

        private static final long serialVersionUID = 4205832525113691806L;
        private String name;
        private Date date;
        private Long longg;

        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Date getDate() {
            return date;
        }
        public void setDate(Date date) {
            this.date = date;
        }
        public Long getLongg() {
            return longg;
        }
        public void setLongg(Long longg) {
            this.longg = longg;
        }
        @Override
        public String toString() {
            return "Thing [name=" + name + ", date=" + date + ", longg=" + longg + "]";
        }
    }

and the web service

    package mypackage;

    import java.util.Arrays;

    import javax.ejb.Stateless;
    import javax.jws.WebService;

    @WebService
    @Stateless
    public class WS {   
        public void doSomething(Thing[] things){
            System.out.println(Arrays.asList(things));
        }
    }

then if you use soapUI to generate the request for you, you'll get something like this



and the result will be (in your server logs)

    [Thing [name=aeoliam venit, date=Sun Sep 28 22:49:45 BRT 2008, longg=10]]

but, of course, you want to send an array of these things, so...





and voila, the result will be

    [Thing [name=aeoliam venit, date=Sun Sep 28 22:49:45 BRT 2008, longg=10], Thing [name=aeoliam venit, date=Sun Sep 28 22:49:45 BRT 2008, longg=10]]

gotcha? :-)

it´s incredible that we just can't find anywhere this answer.

1 comment:

  1. How declare array value in soap
    data[0] = array ('1'=>'a','2'=>'b' and etc..)

    ReplyDelete