delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

Insert byte[] in collection #134

Closed mirsadmrkaljevic closed 7 years ago

mirsadmrkaljevic commented 7 years ago

This is my code: Map<String, Object> query = new HashMap<String, Object>(); byte[] array = new byte[32]; . . query.put("temp" , array); . . mMeteor.insert("chats", query);

In MongoDb I have collection(scheme):

export const Chats = new Mongo.Collection('chats'); ChatsSchema = new SimpleSchema({ temp: { type: Uint8Array, },.... When I use ResultListener in insert method, it give me Error 400 and "{ name ."temp", type : "expectedConstructor" , value : NDQ1NDQ4NDU2MTU2NjQ2NDQ1MzE1NDU2MTU=" }

ocram commented 7 years ago

Good question, thanks!

This ultimately depends on how Jackson serializes your Java data to JSON strings. So you may just as well try serializing this with Jackson alone (if you like) and see what JSON output is produced.

For byte[], Jackson correctly (as per common conventions) interprets this as binary data and returns a Base64 string. So that's not what you want.

Can you try short[] instead? While the size of the numbers is not enforced correctly this way, you may enforce the correct type in your own code. In JavaScript, you could turn a normal array to Uint8Array using the Uint8Array.from method.

Does that help?

mirsadmrkaljevic commented 7 years ago

No, it did not work with short [ ] or int []. I have to convert Base64.String into Uint8Array on server side, and then I solved the problem.

One more question for you. Is this MeteorSingleton thread safe ?

ocram commented 7 years ago

Okay, thanks. That's a useful workaround for now, at least.

Regarding thread safety, I can't really make any guarantees here. Sorry! Looking at other issues, it seems it's rather not safe.