unmarshalling

How does a simple xml element unmarshal to a golang struct?

人盡茶涼 提交于 2019-12-02 03:36:22
问题 Assume the following xml element, with an attribute and a floating point value: <thing prop="1"> 1.23 </thing> <thing prop="2"> 4.56 </thing> In order to unmarshal it, how should I define my struct? type ThingElem struct { Prop int `xml:"prop,attr"` Value float // ??? } type ThingWrapper struct { T ThingElem `xml:"thing"` } // VS type ThingElem struct { XMLName xml.Name `xml:"thing"` // Do I even need this? Prop int `xml:"prop,attr"` Value float // ??? } The usage of the XMLName Property

JaxB reference resolving

两盒软妹~` 提交于 2019-12-02 01:49:13
For the follwing example XML input: <Participants course="someCourse"> <workers> <Worker ref="p3"> <Worker ref="p2"> </workers> <Trainer ref="p1"/> </Participants> <Group id="group1" name="some mixed Person group"> <trainers> <Trainer id="p1" name="John Doe"> </trainers> <workers> <Worker id="p2" name="Jim Scott"> <Worker id="p3" name="Walter Peace"> </workers> </Group> I am trying to make sure that the PersonList in Participants points to the Persons read from group1. (see code snipptes below for the JaxB annotations used). This is just an example for the more generic approach I am seeking. I

JaxB reference resolving

心已入冬 提交于 2019-12-02 01:41:22
问题 For the follwing example XML input: <Participants course="someCourse"> <workers> <Worker ref="p3"> <Worker ref="p2"> </workers> <Trainer ref="p1"/> </Participants> <Group id="group1" name="some mixed Person group"> <trainers> <Trainer id="p1" name="John Doe"> </trainers> <workers> <Worker id="p2" name="Jim Scott"> <Worker id="p3" name="Walter Peace"> </workers> </Group> I am trying to make sure that the PersonList in Participants points to the Persons read from group1. (see code snipptes

JAXB unmarshalling of “generic” real world documents

試著忘記壹切 提交于 2019-12-02 01:29:24
We have a large set of configuration documents of the style <foo> <bar class="com.diedel.Gnarf"> ...more content </bar> <bar class="de.doedel.Bork"> ..more content </bar> ... </foo> The generic implementation classes are all mapped using Jaxb themselves. Before i finally revert to Xstream, a question to the community: Is there a (non hack) way to get this unmarshalled in Jaxb. What we tried so far is "nested" unmarshalling using an @XMLAdapter, where the "bar" field gets an Element, gets the target class and calls another "unmarshall" cycle. This approach has been a) quite slow and b) is

JAXB unmarshall and embedded XSD

依然范特西╮ 提交于 2019-12-02 01:14:08
I have an XML who embed the XSD, so it's something like : <?xml version="1.0" standalone="yes"?> <NewDataSet> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="Table"> <xs:complexType> <xs:sequence> <xs:element name="elem1" type="xs:string" minOccurs="0" /> <xs:element name="elem2" type="xs:string" minOccurs="0" /> <xs:element name="elem3" type=

What if I do not want some variables to be marshalled into XML file?

邮差的信 提交于 2019-12-02 00:59:30
package jaxb.classes; import javax.xml.bind.annotation.*; @XmlAccessorType(XmlAccessType.FIELD) public class Task { @XmlElement(name="input") private String input; // String representing the input file @XmlElement(name="output") private String output; // String representing the output file @XmlElement(name="format") private Format format; // a jaxb.classes.Format representing the format of conversion @XmlElement(name="taskID") private long taskID; // a unique ID for each task. @XmlElement(name="isReady") public boolean isReady; // boolean value representing whether the task is ready for

Golang: Having trouble with nested JSON Unmarshaler

北城以北 提交于 2019-12-01 23:04:15
Given the following code: package main import ( "encoding/json" "log" ) type Somefin string func (s *Somefin) UnmarshalJSON(b []byte) error { log.Println("Unmarshaling",string(b)) *s = Somefin("~"+string(b)+"~") return nil } type Wat struct { A, B string *Somefin } func main() { b := []byte(`{"A":"foo","B":"bar","Somefin":"baz"}`) w := &Wat{Somefin: new(Somefin)} err := json.Unmarshal(b,w) log.Println(w, err) } I get the following output: # go run wat.go 2013/12/14 13:59:17 Unmarshaling {"A":"foo","B":"bar","Somefin":"baz"} 2013/12/14 13:59:17 &{ <nil>} <nil> So the Somefin key is for some

JAXB unmarshalling error: Expected elements are <{ } Root>

主宰稳场 提交于 2019-12-01 21:59:05
问题 I'm reusing existing objects generated elsewhere to unmarshall XML data coming in as a String type. The object: /* 3: */ import java.util.ArrayList; /* 4: */ import java.util.List; /* 5: */ import javax.xml.bind.annotation.XmlAccessType; /* 6: */ import javax.xml.bind.annotation.XmlAccessorType; /* 7: */ import javax.xml.bind.annotation.XmlElement; /* 8: */ import javax.xml.bind.annotation.XmlRootElement; /* 9: */ import javax.xml.bind.annotation.XmlType; /* 10: */ /* 11: */ @XmlAccessorType

Unmarshal JSON in go with different types in a list

独自空忆成欢 提交于 2019-12-01 21:01:32
问题 I have trouble unmarschaling a JSON contruct: { "id": 10, "result": [ { "bundled": true, "type": "RM-J1100" }, [ { "name": "PowerOff", "value": "AAAAAQAAAAEAAAAvAw==" }, { "name": "Input", "value": "AAAAAQAAAAEAAAAlAw==" } ] ] } I actually need the second slice item from the result. My current attempt is type Codes struct { Id int32 `json:"id"` Result []interface{} `json:"result"` } type ResultList struct { Info InfoMap Codes []Code } type InfoMap struct { Bundled bool `json:"bundled"` Type

JAXB unmarshalling error: Expected elements are <{ } Root>

只谈情不闲聊 提交于 2019-12-01 21:01:31
I'm reusing existing objects generated elsewhere to unmarshall XML data coming in as a String type. The object: /* 3: */ import java.util.ArrayList; /* 4: */ import java.util.List; /* 5: */ import javax.xml.bind.annotation.XmlAccessType; /* 6: */ import javax.xml.bind.annotation.XmlAccessorType; /* 7: */ import javax.xml.bind.annotation.XmlElement; /* 8: */ import javax.xml.bind.annotation.XmlRootElement; /* 9: */ import javax.xml.bind.annotation.XmlType; /* 10: */ /* 11: */ @XmlAccessorType(XmlAccessType.FIELD) /* 12: */ @XmlType(name="", propOrder={"policy"}) /* 13: */ @XmlRootElement(name=