erendiler / ksoap2-android

Automatically exported from code.google.com/p/ksoap2-android
0 stars 0 forks source link

Complex Objects - avoiding XML tag in serialization #97

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1.

public class Feature implements KvmSerializable {

public String type;
public String  id;
public String  status;
public Properties properties;

public static final int TYPE = 0;
public static final int ID = 1;
public static final int STATUS = 2;
public static final int PROPERTIES = 3;

public static final String[] names = {"type","id","status","properties"};

public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
        switch(index)
        {
        case TYPE:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = names[TYPE];
            break;
        case ID:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = names[ID];
            break;
        case STATUS:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = names[STATUS];
            break;
        case PROPERTIES:
            info.type = PropertyInfo.VECTOR_CLASS;
            info.name = names[PROPERTIES];
            break;

        default:break;
        }
    }

}

public class Properties extends Vector<Property> implements KvmSerializable {

...

}

2.
androidHttpTransport.call(NAMESPACE + SOAP_ACTION_UPDATE, envelope, headers);

What is the expected output? What do you see instead?

Analyzing androidHttpTransport.requestDump (with androidHttpTransport.debug = 
true) I get:

<feature i:type="n1:Feature">
        <type i:type="d:string">absenceReason</type>
        <id i:type="d:string">1076741</id>
        <status i:type="d:string">Enabled</status>
        <properties i:type="n1:Properties">
          <property i:type="n1:Property">
            <name i:type="d:string">absenceReasons.1</name>
            <value i:type="d:string">meeting</value>
          </property>
          <property i:type="n1:Property">
            <name i:type="d:string">absenceReasons.2</name>
            <value i:type="d:string">travelling</value>
          </property>
        </properties>
</feature>

I would like to avoid the tag <properties>, i.e.:

<feature i:type="n1:Feature">
        <type i:type="d:string">absenceReason</type>
        <id i:type="d:string">1076741</id>
        <status i:type="d:string">Enabled</status>
          <property i:type="n1:Property">
            <name i:type="d:string">absenceReasons.1</name>
            <value i:type="d:string">meeting</value>
          </property>
          <property i:type="n1:Property">
            <name i:type="d:string">absenceReasons.2</name>
            <value i:type="d:string">travelling</value>
          </property>
</feature>

Please provide any additional information below.

Ultimately it is the method 
SoapSerializationEnvelope.writeObjectBody(XmlSerializer writer, SoapObject obj) 
that calls the code responsible for writing the tag:

writer.startTag(nestedSoap.getNamespace(), nestedSoap.getName());
writeObjectBody(writer, 
nestedSoap);                writer.endTag(nestedSoap.getNamespace(), nestedSoap.getName());

I believe I can fix this issue by overloading writeObjectBody, adding a third 
parameter (a list of tags to be avoided). However, this is not an elegant 
solution.

Another possible way of fixing this would be to create a 
PropertyInfo.VECTOR_CLASS_WITHOUT_TAG.

Original issue reported on code.google.com by ram...@gmail.com on 16 Dec 2011 at 5:54

GoogleCodeExporter commented 8 years ago
Fork the code on github and implement a suitable and backwards compatible 
change and send a pull request. I can pull it in and cut a new release..

Original comment by mosa...@gmail.com on 16 Dec 2011 at 9:09

GoogleCodeExporter commented 8 years ago
Is there any fix you would like to contribute or should I close this issue?

Original comment by mosa...@gmail.com on 30 Apr 2012 at 6:32

GoogleCodeExporter commented 8 years ago
you can close this issue.

Original comment by ram...@gmail.com on 5 May 2012 at 11:16

GoogleCodeExporter commented 8 years ago

Original comment by mosa...@gmail.com on 6 May 2012 at 3:19

GoogleCodeExporter commented 8 years ago

Original comment by mosa...@gmail.com on 6 May 2012 at 3:20

GoogleCodeExporter commented 8 years ago

Original comment by mosa...@gmail.com on 6 May 2012 at 3:21

GoogleCodeExporter commented 8 years ago
Did you solved this problem? what did you do?

Original comment by ignak...@gmail.com on 26 May 2014 at 7:29