i have simple xml response third-party api.
let's looks like
<items> <item name="name1"/> <item name="name2"/> <item name="name3"/> </items>
having case classes
case class items(children: list[item]) case class item(name: string)
how can write unmarshaller use implicitly work code this:
unmarshal(myxmlstring).to[items].map ...
or better
unmarshal(myxmlstring).to[list[item]].map ...
can without defining unmarshal functions explicitly access xml? data have looks declarative enough have unmarshalling without additional boilerplate.
scala-xml doesn't provide deserializer hydrate custom objects. if requirement simple mentioned in sample example, can try below:
scala> val itemsstring = "<items><item name='name1'/><item name='name2'/><item name='name3'/></items>" scala> val itemsxml = scala.xml.xml.loadstring(itemsstring) scala> val items = items(( itemsxml \\ "@name").tolist.map(( x=> item(x.tostring)) )) │
Comments
Post a Comment