1

My class is annotated as

@Root
public class Geonames {
    @Path("intersection/street1")
    @Element
    public String street1;

    @Path("intersection/highway1")
    @Element
    public String highway1;

    @Path("intersection/street2")
    @Element
    public String street2;

    @Path("intersection/highway2")
    @Element
    public String highway2;

    @Path("intersection/lat")
    @Element
    public String lat;

    @Path("intersection/lng")
    @Element
    public String lng;

    @Path("intersection/distance")
    @Element
    public String distance;
}

The XML is as such:

<geonames>
    <intersection>
        <street1>11th Street</street1>
        <highway1>residential</highway1>
        <street2>Campbell Street</street2>
        <highway2>unclassified</highway2>
        <lat>37.8098123</lat>
        <lng>-122.2969874</lng>
        <distance>0.07</distance>
    </intersection>
</geonames>

But I get the error:

05-26 23:46:46.511: E//RequestProcessor.java:250(23618): Caused by:
org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy
@org.simpleframework.xml.Element(data=false, name=, required=true, type=void) on field
'street1' public java.lang.String com.mosier.securityapp.geonames.Geonames.street1 for
class com.mosier.securityapp.geonames.Geonames at line 4

This seems to indicate that street1 has not value, but of course it does. My annotation or class must be set up wrong, but I'm too new to this to see what's going. Is there an easy fix I'm overlooking?

2
  • Point --When implementing a serialisation/de-serialisation scenario I always do a serialisation first to rule out any incorrect XML, and --If you have an error on the first element it is likely you have a fundamental problem with the whole thing. -- do you need a geonames/intersection/.. rather than just an intersection/.. in your @Path Commented May 27, 2013 at 6:55
  • I believe I tried that as well, got different errors. I was able to resolve this by doing it as nested objects rather than using more complicated @Paths. Good point on the serialization. I'll look into your solution. Commented May 27, 2013 at 19:18

1 Answer 1

1

Try this

@Root
public class Geonames {
    @Path("intersection")
    @Element
    public String street1;

    @Path("intersection")
    @Element
    public String highway1;

    @Path("intersection")
    @Element
    public String street2;

    @Path("intersection")
    @Element
    public String highway2;

    @Path("intersection")
    @Element
    public String lat;

    @Path("intersection")
    @Element
    public String lng;

    @Path("intersection")
    @Element
    public String distance;
}
Sign up to request clarification or add additional context in comments.

1 Comment

oh really. So the @Path annotation specifies the path to the element, minus the element itself. I guess that's what I was missing.

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.