How to send an object via SOAP Web service

8

To send a primitive data is simple, but when it comes to complex data like the one shown below, an exception is thrown:

  

java.lang.RuntimeException: Can not serialize: Person {name = given, address = given etc ...}

Most of the tutorials and examples address the use of primitive types rather than complex types like the one presented here.

Given an object represented below:

public class Pessoa {
    private String nome;
    private String endereco;
    private List<String> emails;
    private boolean ativo;

    // getters e setters

    @Override
    public String toString(){
        return "Pessoa{nome="+dado+", endereco="+dado+" etc...}";
    }
}

How to send it to a web service with the SOAP standard using the kSOAP library?

    
asked by anonymous 09.01.2015 / 20:39

3 answers

1

I do not know if this is the correct answer, because I have no way to test what you are doing. But I'll try to respond anyway:

  

java.lang.RuntimeException: Can not serialize: Person {name = given, address = given etc ...}

This message occurs because you attempted to serialize a person and when the exception was raised, the toString() method of the person was invoked to construct the exception message.

Normally, serializable objects implement the Serializable interface and contain all serializable fields. Primitive types are serializable, String is serializable. If the class that implements its List is serializable (almost all are, including ArrayList ) and all list elements are serializable then the entire list is serializable.

So maybe your solution is just to add implements Serializable to the class definition.

    
10.01.2015 / 00:52
1

You have to implement the Serializable Interface

public class Employee implements java.io.Serializable
{
  public String name;
  public String address;
  public transient int SSN;
  public int number;

  public void mailCheck()
  {
     System.out.println("Mailing a check to " + name + " " + address);
  }
}
    
16.06.2016 / 13:27
1

You do not send the entire Person object, it would be best to create an object serializer. A SOAP message is nothing more than a STRING with an XML format following a few different patterns.

Example quoted above is on the site: serializer & deserializer

    
01.12.2016 / 10:13