Github user brodybits commented on the pull request:
https://github.com/apache/cordova-wp8/pull/79#issuecomment-99931329
The Newtonsoft JSON library does seem much easier to use and perhaps more
efficient as well, but unlike the .NET JSON `DataContractJsonSerializer`,
Newtonsoft does not support serialization of arbitrary types. This becomes a
problem with the cordova-file-plugin when it attempts to send a PluginResult
with a byte array (`byte[]`) in response to a `readAsArrayBuffer` request. This
is the cause of CB-8968, and it could affect other plugins as well.
I have identified two alternative solutions to fix CB-8968:
I. Fix `File.cs` in cordova-plugin-file to send the `PluginResult` with a
normal integer array:
```diff
--- a/src/wp/File.cs
+++ b/src/wp/File.cs
@@ -695,7 +695,10 @@ public void readAsArrayBuffer(string options)
buffer = readFileBytes(filePath, startPos, endPos,
isoFile);
}
- DispatchCommandResult(new
PluginResult(PluginResult.Status.OK, buffer), callbackId);
+ int[] bufferAsIntArray = new int[buffer.Length];
+ for (int i=0; i<buffer.Length; ++i) bufferAsIntArray[i] =
buffer[i];
+
+ DispatchCommandResult(new
PluginResult(PluginResult.Status.OK, bufferAsIntArray), callbackId);
}
catch (Exception ex)
{
```
Idea thanks to:
http://stackoverflow.com/questions/15226921/how-to-serialize-byte-as-simple-json-array-and-not-as-base64-in-json-net
II. In `template/cordovalib/JSON/JsonHelper.cs` add a new function such as
`public static string SerializeAny(object obj)` with what used to be the
contents of `JSON.JsonHelper.Serialize`, and call this function instead of
`JsonConvert.SerializeObject` in `PluginResult.cs`.
I am not sure which solution would have better performance. Solution II
only goes through the data once, but solution II delegates the looping to the
framework libraries, which *could* do the hard work in C/C++/assembly.
I am happy to issue a PR for either solution. Solution I would be easiest.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]