Reputation: 589
My mobile app calls a JSON service and converts the JSON into custom objects I've created. Is there any easy way to pass a List<MyObject>
to the watch?
I looked into the DataMap object and I don't see an easy way to do it. It looks like my options are to either serialize my object BACK into JSON and send as a String or convert my objects into List<DataMap>
.
Is there any way the framework can do this for me?
Thanks.
Upvotes: 0
Views: 565
Reputation: 91
I solved this problem using protocol buffers. The Square people have a compact protobuf library for Android (https://github.com/square/wire) that makes this really easy. You write a .proto file for the messages you want to send across the wire and the compiler generates Java classes for you. You load those classes with whatever content, lists of things, etc., and the generated code includes methods that convert the data structures to arrays of bytes and back again. Once you've got an array of bytes, you can ship those back and forth however you like.
Upvotes: 1
Reputation: 2701
I really don't think so. I thought it would be clever to store my (Parcelable) custom object into a Bundle and using dataMap.toBundle() and DataMap.fromBundle(), but it didn't work. Those methods just ignore anything in the Bundle that isn't already part of the DataMap api!
Upvotes: 1