json.Unmarshal returning blank structure

Your struct fields are not exported. This is because they start with a lowercase letter. EntryCount // <— Exported entryCount // <— Not exported When I say “not exported”, I mean they are not visible outside of your package. Your package can happily access them because they are scoped locally to it. As for the … Read more

when does JAXB unmarshaller.unmarshal returns a JAXBElement or a MySchemaObject?

If the root element uniquely corresponds to a Java class then an instance of that class will be returned, and if not a JAXBElement will be returned. If you want to ensure that you always get an instance of the domain object you can leverage the JAXBInstrospector. Below is an example. Demo package forum10243679; import … Read more

Is there a package to marshal in and out of x-www-form-urlencoding in golang

gorilla/schema is popular and well maintained: e.g. func FormHandler(w http.RequestWriter, r *http.Request) { err := r.ParseForm() if err != nil { // handle error } person := new(Person) // Person being a struct type decoder := schema.NewDecoder() err = decoder.Decode(person, r.Form) if err != nil { // handle error } } goforms is also an … Read more

How to unmarshal JSON into durations?

The lack of JSON marshaling and unmarshaling methods on time.Duration was an unfortunate oversight. This should hopefully be resolved in Go2 (see issue #10275). You can, however, define your own type around time.Duration that supports marshaling to the string representation of the duration and unmarshaling from either the numeric or string representations. Here is an … Read more

Unmarshal CSV record into struct in Go

There is gocarina/gocsv which handles custom struct in the same way encoding/json does. You can also write custom marshaller and unmarshaller for specific types. Example: type Client struct { Id string `csv:”client_id”` // .csv column headers Name string `csv:”client_name”` Age string `csv:”client_age”` } func main() { in, err := os.Open(“clients.csv”) if err != nil { … Read more

How to fix Unmarshalling unknown type code XXX at offset YYY in Android?

There’s some rules for write and read parcelables. 1- Be careful about type mismatch. If you write int, don’t try to read long etc. 2- Be careful about order of writes and reads. Objects must be at the same sort order when reading and writing. Both of these can cause “Unmarshalling unknown type code”.

How to marshall and unmarshall a Parcelable to a byte array with help of Parcel?

First create a helper class ParcelableUtil.java: public class ParcelableUtil { public static byte[] marshall(Parcelable parceable) { Parcel parcel = Parcel.obtain(); parceable.writeToParcel(parcel, 0); byte[] bytes = parcel.marshall(); parcel.recycle(); return bytes; } public static Parcel unmarshall(byte[] bytes) { Parcel parcel = Parcel.obtain(); parcel.unmarshall(bytes, 0, bytes.length); parcel.setDataPosition(0); // This is extremely important! return parcel; } public static <T> … Read more

“BadParcelableException: ClassNotFoundException when unmarshalling ” while using Parcel.read method that has a ClassLoader as argument

Don’t unmarshall a custom class (i.e. one provided by your application and not by the Android framework) with the framework class loader that is used when you give null as the ClassLoader argument. Use the application class loader: parcel.readList(myclassList, getClass().getClassLoader()); Whenever a Parcel.read*() method also has a ClassLoader as an argument (e.g. Parcel.readList(List outVal, ClassLoader … Read more