unmarshalling

How do I unmarshal a string value from a JSON document into a variable of type int?

那年仲夏 提交于 2019-12-13 11:05:53
问题 My struct: type User struct { FirstName string `json:"firstname, omitempty" validate:"required"` LastName string `json:"lastname, omitempty" validate:"required"` NumberofDays int `json:"numberofdays, string" validate:"min=0,max=100"` } Value for NumberofDays is passed as string from the server but I want to check if it is within range and store as int. Ex: user := &User{"Michael","Msk","3"} I'm getting 'cannot unmarshal string into Go value of type int'. I'm not sure how to typecast to int

Unmarshalling jaxB doesn't work, objects null

青春壹個敷衍的年華 提交于 2019-12-13 01:34:26
问题 I have a problem with jaxB. There is no exception and here is my xml ; <event> <event_datetimeGMT>2015-02-27 17:00</event_datetimeGMT> <gamenumber>443364144</gamenumber> <sporttype>Basketball</sporttype> <league>Adriatic</league> <IsLive>No</IsLive> <participants> <participant> <participant_name>Cedevita</participant_name> <contestantnum>1001</contestantnum> <rotnum>1001</rotnum> <visiting_home_draw>Home</visiting_home_draw> </participant> <participant> <participant_name>Mega Leks<

Unexpected element while unmarshalling

可紊 提交于 2019-12-13 00:29:30
问题 I have to pull information from a webservice. Here's an example of a response: <myServices> <myService name="A" serviceId="a" type="rest" version="1.0"> <entryPoints/> </myService> <myService name="B" serviceId="b" type="rest" version="1.0"> <entryPoints/> </myService> <myService name="C" serviceId="C" type="rest" version="1"> <entryPoints> <entryPoint realm="external" wadl="http://myURL.com/1/app.wadl>http://myURL.com/1</entryPoint> </entryPoints> </myService> <myService name="D" serviceId=

How to tell json.Unmarshal to use struct instead of interface

一笑奈何 提交于 2019-12-12 13:57:20
问题 I want to write a function that receives several types of structs and unmarshals them from JSON. To this end, I have another set of functions with a pre-defined signature that return the struct instances but since each function returns a different type of struct the function signature has interface{} as the return type. When I send json.Unmarshal a concrete struct it works as I expected but when I send the same struct as interface{} it converts it to a map. Here is a simplified example code

How to unmarshal from interface{} to interface{} in Go

爷,独闯天下 提交于 2019-12-12 13:48:10
问题 There are multiple nodes in my system which communicate through RPC. I am trying to send a map[string] interface{} to another node through RPC. Sender uses json.Marshal and receiver uses json.Unmarshal to get the map. Let us say at the sender side, map contains [1] => 2 where 2 is of type uint32. The problem is Unmarshal tries to find the type of underlying data and converts 2 to float64 type according to its default behavior as specified here https://blog.golang.org/json-and-go. Later,

Unmarshalling SOAP Envelope from file in Java

不羁岁月 提交于 2019-12-12 12:13:08
问题 I want to unit-test the mapper objects that map/translate web service types generated by wsimport in to my own domain objects. I also want to test error-scenarios, such as SOAP faults and such, and I am thinking it would be best to test the mapper objects on authentic SOAP responses. I do not want to fire requests to the web service itself as this requires access to the web service, and poses round-trip time for each test. Given this scenario, I am seeking to unmarshal SOAP messages from a

Unmarshal Nested xml with Go

£可爱£侵袭症+ 提交于 2019-12-12 09:16:26
问题 I have the following snippet of code that I have been banging my head on the wall trying to make it work. I have searched everywhere for a solution, but none of the ones that I have found seem to work. It seems that I have an issue with my mapping for the xml.Unmarshal command as it pertains to nested fields. The code below works for retrieving the first value which is called unit , and is on the top level of the xml code. The other two fields come up as zero, and they are nested two level

JAXB: How can I unmarshal XML without namespaces

天涯浪子 提交于 2019-12-12 07:49:05
问题 I have an XML file: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <object> <str>the type</str> <bool type="boolean">true</bool> </object> And I want to unmarshal it to an object of the class below @XmlRootElement(name="object") public class Spec { public String str; public Object bool; } How can I do this? Unless I specify namespaces (see below), it doesn't work. <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <object> <str>the type</str> <bool xmlns:xsi="http://www.w3.org

How do i use java boolean condition in camel route?

荒凉一梦 提交于 2019-12-12 05:15:43
问题 I am using camel to transfer files from one endpoint to another. I am starting multiple routes in which some routes need to decrypt the files. How can i make the unmarshal process optional in a specific route based on a boolean condition? from(source) .choice() .when(isEncrypted())) //Java boolean value .unmarshal(decrypt(pgpEncryptionDetails)) .endChoice() to(destination); PGPDataFormat decrypt(PGPEncryptionDetails pgpEncryptionDetails) { PGPDataFormat pgpDataFormat = new PGPDataFormat();

CXF SOAP JAX-WS WSS4JInInterceptor change namespace and cause Unmarshalling error

↘锁芯ラ 提交于 2019-12-12 04:50:34
问题 I'm using WSS4JInInterceptor in my endpoint to validate the authorization. I have that in my endpoint Here it's my SOAP message <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header> <wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsse:UsernameToken wsu:Id=