cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brodybits <>
Subject [GitHub] cordova-wp8 pull request: Added Newtonsoft json dll
Date Thu, 07 May 2015 16:33:52 GMT
Github user brodybits commented on the pull request:
    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
    --- 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),
    +                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),
                 catch (Exception ex)
    Idea thanks to:
    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 or file a JIRA ticket
with INFRA.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message