unmarshalling

How to unmarshal a field that can be an array or a string in Go?

不问归期 提交于 2019-12-02 10:18:20
I'm trying to unmarshal this file: { "@babel/code-frame@7.0.0": { "licenses": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-code-frame", "publisher": "Sebastian McKenzie", "email": "sebmck@gmail.com", "path": "/Users/lislab/workspace/falcon-enrolment/frontend-customer/node_modules/@babel/code-frame", "licenseFile": "/Users/lislab/workspace/falcon-enrolment/frontend-customer/node_modules/@babel/code-frame/LICENSE" }, "json-schema@0.2.3": { "licenses": [ "AFLv2.1", "BSD" ], "repository": "https://github.com/kriszyp/json-schema", "publisher": "Kris Zyp", "path":

go json unmarshal options [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-02 09:16:43
This question already has an answer here: Unmarshalling a JSON that may or may not return an array? 2 answers Trying to find a simple solution to marshaling/unmashaling into the following struct type Resource struct { Data []ResourceData `json:"data"` } type ResourceData struct { Id string `json:"id"` Type string `json:"type"` Attributes map[string]interface{} `json:"attributes"` Relationships map[string]Resource `json:"relationships"` } r := Resource{} json.Unmarshal(body, &r) this is great if: body = `{"data":[{"id":"1","type":"blah"}]}` However I also need it to respond to: body = `{"data":

org.xmlpull.v1.XmlPullParserException

我们两清 提交于 2019-12-02 08:35:58
I'm trying to bind an xml file(as a byte[] ) to a java object. This is my code- public voidinputConfigXML(String xmlfile, byte[] xmlData) { IBindingFactory bFact = BindingDirectory.getFactory(GroupsDTO.class); IUnmarshallingContext uctx = bFact.createUnmarshallingContext(); groups = (GroupsDTO) uctx.unmarshalDocument(new ByteArrayInputStream(xmlData), "UTF8"); } The unmarshalDocument() is giving me this exception. What do i do? FYI: Running as JUnit test case The following is the stacktrace - Error parsing document (line 1, col 1) org.xmlpull.v1.XmlPullParserException: only whitespace content

Partially specialize methods of variadic template classes

自作多情 提交于 2019-12-02 08:28:09
I want to write an unmarshaller to extract arguments stored in a msgpack array for individual arguments to a call of sigc::signal::emit(...) . I tried this: template<class... T> class MsgpackAdapter: public MsgpackAdapterBase { public: MsgpackAdapter (sigc::signal<void, T...> &sig) : MsgpackAdapterBase (), signal_ (sig) {} protected: virtual void do_emit (const msgpack::object_array &mp_args) override; private: sigc::signal<void, T...> signal_; }; template<class T1> void MsgpackAdapter<T1>::do_emit (const msgpack::object_array &mp_args) { T1 a1; mp_args.ptr[0].convert (a1); signal_.emit (a1);

JAXB Unmarshalling XML string - Looping through all tags

纵然是瞬间 提交于 2019-12-02 07:17:48
I am new to Java programming and I am doing Unmarshalling the following XML string. My task is get the names of the customers in this string. I have done it for one customer. I need to get all the customer names. I need help on the looping part. This works for one customer My Java code: XMLInputFactory xif = XMLInputFactory.newFactory(); Reader reader = new StringReader(response.toString()); XMLStreamReader xsr = xif.createXMLStreamReader(reader); while(xsr.hasNext()) { if(xsr.isStartElement() && xsr.getLocalName().equals("customer")) { break; } xsr.next(); } JAXBContext jc = JAXBContext

JAXB unmarshall and embedded XSD

荒凉一梦 提交于 2019-12-02 06:32:55
问题 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"

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

空扰寡人 提交于 2019-12-02 05:55:23
问题 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

JAXB unmarshalling of “generic” real world documents

馋奶兔 提交于 2019-12-02 04:54:12
问题 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

How do I serialize & deserialize CSV properly?

浪尽此生 提交于 2019-12-02 04:32:54
I've been trying to serialize an object to a CSV String but the object contains a List and @JsonUnwrapped doesn't work on List objects. Expected sample output : color,part.name\n red,gearbox\n red,door\n red,bumper Actual output : com.fasterxml.jackson.core.JsonGenerationException: Unrecognized column 'name': Here is my code : (Most of it is the 2 POJO's) import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml

Issue with namespaces in XMLs in JAXB unmarshalling

≯℡__Kan透↙ 提交于 2019-12-02 03:58:47
I have an XML to unmarshall with JAXB. The code works fine if I remove all namespace attributes from the elements but I get a null object after unmarshalling if I keep the namespace attributes. The XML is like this: <Animal xmlns="http://allmycats.com/serviceplatform/1.0/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <Cat z:Id="i3" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <name>kitty</name> </Cat> <Cat z:Id="i2" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <name>kitty2</name> </Cat> </Animal> My Animal bean is like this: @XmlRootElement(name =