2

I'm trying to deserialize an object on an Android device using SimpleXML. In a maven file I used dependency with exclusions (I followed an advice in an another question, as without excluding these dependencies, I couldn't start the application):

<dependency>
    <groupId>org.simpleframework</groupId>
    <artifactId>simple-xml</artifactId>
    <version>2.6.7</version>
     <exclusions>
    <!-- StAX is not available on Android -->
    <exclusion>
        <artifactId>stax</artifactId>
        <groupId>stax</groupId>
    </exclusion>
    <exclusion>
        <artifactId>stax-api</artifactId>
        <groupId>stax</groupId>
    </exclusion>
    <!-- Provided by Android -->
    <exclusion>
        <artifactId>xpp3</artifactId>
        <groupId>xpp3</groupId>
    </exclusion>
</exclusions>

For testing I wrote just a simple class:

class Test {
        String s;
    }

and I try to get an object:

Test t = null;
try {
    t = serializer.read(Test.class, source);
} catch (Exception e) {
    e.printStackTrace();
}

Log.v("t",t.s);

but in the last line, while I try to read the field t.s, I'm getting errors like:

Could not find method javax.xml.stream.XMLInputFactory.newInstance, referenced from method org.simpleframework.xml.stream.StreamProvider.<init>

unable to resolve static method 3372: Ljavax/xml/stream/XMLInputFactory;.newInstance ()Ljavax/xml/stream/XMLInputFactory;

dead code 0x0006-0009 in Lorg/simpleframework/xml/stream/StreamProvider;.<init> 

unable to find class referenced in signature (Ljavax/xml/stream/XMLEventReader;)

What can be the cause of the problem and how can I solve it?

3
  • please let us know what the other question is. Otherwise you might want to remove your excluse and use the latstet Simplxml - framework version and go from there. Commented Dec 23, 2012 at 23:59
  • @wolfgang-fahl The other question was here: stackoverflow.com/questions/5964668/… Eventually I used Gson and which I didn't have any problem with. Commented Dec 27, 2012 at 9:20
  • Can you post your xml please? Commented Jan 4, 2013 at 0:07

1 Answer 1

1

You have to add annotations to your class. I made a small test with Simple XML 2.6.9 (simple-xml-2.6.9.jar only) --> no problems.

XML:

<test>
   <s>abc</s>
</test>

Test class:

@Root
public class Test
{
    @Element
    String s;


    @Override
    public String toString()
    {
        return "Test{" + "s=" + s + '}';
    }
}

Deserializing XML:

final File f =  ...


Serializer ser = new Persister();
Test t = ser.read(Test.class, f);

System.out.println(t);

Output:

Test{s=abc}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.