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”.

Why does JAXB need a no arg constructor for marshalling?

When a JAXB (JSR-222) implementation initializes its metadata it ensures that it can support both marshalling and unmarshalling. For POJO classes that do not have a no-arg constructor you can use a type level XmlAdapter to handle it: http://blog.bdoughan.com/2010/12/jaxb-and-immutable-objects.html java.sql.Date is not supported by default (although in EclipseLink JAXB (MOXy) it is). This can also … Read more

JAXB Marshalling with null fields

Thanks guys for your answers. Chris Dail – I tried your approach, and it didn’t really do what I wanted. JAXB was still ignoring my null values, in spite of defining a default value for my fields. I did stumble across the answer after somebody in the Jersey forums pointed me to documentation section 2.2.12.8 … Read more

C# – How To Convert Object To IntPtr And Back?

So if I want to pass a list to my callback function through WinApi I use GCHandle // object to IntPtr (before calling WinApi): List<string> list1 = new List<string>(); GCHandle handle1 = GCHandle.Alloc(list1); IntPtr parameter = (IntPtr) handle1; // call WinAPi and pass the parameter here // then free the handle when not needed: handle1.Free(); … Read more

JSON unmarshaling with long numbers gives floating point number

There are times when you cannot define a struct in advance but still require numbers to pass through the marshal-unmarshal process unchanged. In that case you can use the UseNumber method on json.Decoder, which causes all numbers to unmarshal as json.Number (which is just the original string representation of the number). This can also useful … Read more

C++ .NET convert System::String to std::string

There is cleaner syntax if you’re using a recent version of .net #include “stdafx.h” #include <string> #include <msclr\marshal_cppstd.h> using namespace System; int main(array<System::String ^> ^args) { System::String^ managedString = “test”; msclr::interop::marshal_context context; std::string standardString = context.marshal_as<std::string>(managedString); return 0; } This also gives you better clean-up in the face of exceptions. There is an msdn article … 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

Json Java serialization that works with GWT [closed]

Take a look at GWT’s Overlay Types. I think this is by far the easiest way to work with JSON in GWT. Here’s a modified code example from the linked article: public class Customer extends JavaScriptObject { public final native String getFirstName() /*-{ return this.first_name; }-*/; public final native void setFirstName(String value) /*-{ this.first_name = … Read more