dimvisio / ksoap2-android

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

Attributes do not load for my KvmSerializable #74

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a custom complex object.
2. Make a web service call
3.

What is the expected output? What do you see instead?
My object is public class Author extends AttributeContainer implements 
KvmSerializable. However, it should load some attributes associated with it, 
but it does not.

What version of the product are you using? On what operating system?
2.5.7

Please provide any additional information below.
Is there anything I am missing? My object gets correctly created with all its 
properties, but not with the attributes.

Original issue reported on code.google.com by dnkoutso@gmail.com on 27 Jul 2011 at 9:31

GoogleCodeExporter commented 8 years ago
I can patch this:

                if (obj instanceof AttributeContainer) {
                    for (int counter = 0; counter < parser.getAttributeCount(); counter++)
                    {
                        String attributeName = parser.getAttributeName(counter);
                        String value = parser.getAttributeValue(counter);
                        ((AttributeContainer) obj).addAttribute(attributeName, value);
                    }
                }

In method:

protected void readSerializable(XmlPullParser parser, KvmSerializable obj) 
throws IOException, XmlPullParserException

This way if we have a custom object that extends AttributeContainer and 
implements KvmSerializable you can get the attributes.

You may also extend SoapObject for your custom object, this should work.

Original comment by dnkoutso@gmail.com on 28 Jul 2011 at 12:27

GoogleCodeExporter commented 8 years ago
How about you patch it and provide patch files or a pull request on github 

Original comment by mosa...@gmail.com on 28 Jul 2011 at 2:24

GoogleCodeExporter commented 8 years ago
Ok I will be doing that shortly.

Original comment by dnkoutso@gmail.com on 5 Aug 2011 at 3:22

GoogleCodeExporter commented 8 years ago
Great. I look forward to the patch. Make sure the project builds... and contact 
me here if you need help.

Original comment by mosa...@gmail.com on 5 Aug 2011 at 5:06

GoogleCodeExporter commented 8 years ago

Original comment by mosa...@gmail.com on 5 Aug 2011 at 5:06

GoogleCodeExporter commented 8 years ago
If you call protected void readSerializable(XmlPullParser parser, SoapObject 
obj) throws IOException it should already do that  .. can you test and 
potentially patch as needed.. 

Original comment by mosa...@gmail.com on 23 Aug 2011 at 5:22

GoogleCodeExporter commented 8 years ago
Any update on this patch dnkoutso?

Original comment by mosa...@gmail.com on 18 Nov 2011 at 4:59

GoogleCodeExporter commented 8 years ago
I am actually not sure where to insert that code snippet in the method 
correctly. Can you paste the complete version that works for you or provide a 
patch/pull request?

Original comment by mosa...@gmail.com on 18 Nov 2011 at 5:29

GoogleCodeExporter commented 8 years ago
I can confirm, that dnkoutso patch works if you insert it at beginning of 
readSerializable(XmlPullParser parser, KvmSerializable obj) just before while 
(parser.nextTag() != XmlPullParser.END_TAG)
But IMHO it`s not very efficient when you need some of the attributes, but not 
all of them. In my example there are 22 attributes and I only need 2-3 of them. 
:) 

Original comment by vuk...@gmail.com on 1 Feb 2012 at 10:11

GoogleCodeExporter commented 8 years ago
O.k. I think i have an idea. Extend KvmSerializable:
public interface KvmSerializableWithAttributes extends KvmSerializable {
    ArrayList<String> AttributesNeeded();
}

All serializing classes, that needs attribute support should look like this:
public class Row extends AttributeContainer implements 
KvmSerializableWithAttributes {
@Override
public ArrayList<String> AttributesNeeded() {
    ArrayList<String> arrList = new ArrayList<String>();
    arrList.add("ows_LinkTitle");
    arrList.add("ows_AssignedTo");
    arrList.add("ows_Author");      
    return arrList;
}
<...>

Then in
/** Read a KvmSerializable. */
protected void readSerializable(XmlPullParser parser, KvmSerializable obj) 
throws IOException,
XmlPullParserException
{
    int testIndex = -1; // inc at beg. of loop for perf. reasons
    int propertyCount = obj.getPropertyCount();
    PropertyInfo info = new PropertyInfo();
    //AttributeFix-->
    //if (obj instanceof AttributeContainer) {
    if (obj instanceof KvmSerializableWithAttributes) {         
        formAttributes(parser,obj);
    }                   
    //<--AttributeFix   
<...>   

Additional member in SoapSerializationEnvelope class:
protected void formAttributes(XmlPullParser parser, KvmSerializable obj)
{           
    ArrayList<String>               arrList = new ArrayList<String>();
    KvmSerializableWithAttributes   kvmSerializableWithAttributes;
    kvmSerializableWithAttributes = (KvmSerializableWithAttributes) obj;
    arrList = kvmSerializableWithAttributes.AttributesNeeded();
    for (int counter = 0; counter < parser.getAttributeCount(); counter++)
    {
        if(arrList.contains(parser.getAttributeName(counter)))
        {
            String attributeName = parser.getAttributeName(counter);
            String value = parser.getAttributeValue(counter);
            ((AttributeContainer) obj).addAttribute(attributeName, value);
        }
    }
}

Original comment by vuk...@gmail.com on 1 Feb 2012 at 10:37

GoogleCodeExporter commented 8 years ago
This should work now with some of the changes in the recent releases. Can you 
try with 2.6.3 and confirm?

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

GoogleCodeExporter commented 8 years ago
No further feedback so I am closing this issue.

Original comment by mosa...@gmail.com on 24 May 2012 at 4:08