B4J Question B4J Serializator and Google Map Markers

aminoacid

Active Member
Licensed User
Longtime User
I'm wondering why the B4J Serializator cannot serialize a Google Map Marker to Bytes but the B4i Serializator can serialize it.

For example if I have the following test code snippet:

Dim m As Marker
m=gmap.AddMarker(0,0,"D")
mqtt.Publish(mytopic, serializator.ConvertObjectToBytes(m))

I get the following exception in B4J but it works fine in B4I:

main._btnpublish_click (java line: 300)
java.lang.RuntimeException: Cannot serialize object: com.lynden.gmapsfx.javascript.object.Marker@50758e36
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:258)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:224)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:104)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(B4XSerializator.java:62)
at com.praxsoft.b4j.BoatMate.main._btnpublish_click(main.java:300)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
 

aminoacid

Active Member
Licensed User
Longtime User
Yes, I had initially created a custom type with a marker as part of the type. When I went to serialize the custom type, I got the same exception. I then narrowed it down to the marker itself with the above test code. So as you say, eliminating the marker from the custom type should work.

However I'm porting over some code from B4I where the B4I serializator does not seem to have a problem with serializing a custom type containing a marker to bytes. So I was a bit confused and was wondering why there was a discrepancy. I have not tried it with B4A but I will if I get a chance.

Anyway, for now, I'll do as you suggest and modify the code to create the custom type without the marker but just it's components.

Thanks Erel.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Ideally it should have thrown the same error in B4i. It is not always possible to know whether an object is a B4X custom type or not. In the case of Marker it treated it as a custom B4X type and successfully serialized it.

You should only use B4XSerializator with the documented types: primitives, strings, collections, arrays of bytes and user types. The collections and user types can only hold types from that list.
 
Upvote 0
Top