Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java XML converter to POJO  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I have been stuck on a problem for a while. I've been having trouble to convert this http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml xml document to a POJO class since there are multiple 'Cube' tags. Can anyone here help me on how a valid pojo class would look like?


this is my setup so far, but it is obviously not working.
 
Saloon Keeper
Posts: 8900
167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

  • The root isn't named Gesmes, but Envelope.
  • Envelope doesn't have a name, Sender has a name.
  • Envelope doesn't have a time, the inner Cube has a time.
  • Envelope doesn't have a list of Cube, it just has a single Cube.
  • Cube doesn't contain a Cube:currency element list, it contains a Cube element list of Cube elements.
  • You still need to set namespaces on your elements.
  •  
    Sammy Ward
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I created the following classes:



    But I now get this error: " org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.Attribute(empty=, name=name, required=true) on field 'name' private from class Sender"
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 8900
    167
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    name is not an attribute of Sender, but a child element.

    You also still need to specify the namespaces properly.
     
    Sammy Ward
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the help so far, I'm not quite sure how to use namepaces. I have managed to convert everything except time to java classes.



    I'm not quite sure how to get the time value, would be really thankful if you could help me with that. Thanks.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 8900
    167
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well, as you can see, Envelope, subject, Sender and name use the gesmes prefix, while Cube, time, currency and rate don't use a prefix. In the document's root element, gesmes is declared as a short-hand for the "http://www.gesmes.org/xml/2002-08-01" namespace, and the default namespace is "http://www.ecb.int/vocabulary/2002-08-01/eurofxref".

    You still need to properly annotate your classes and members with these namespaces:

    Now, when you say you can't convert time, what is happening?
     
    If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
    Rocket Oven Kickstarter - from the trailboss
    https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!