I'm working on a wrapper for dropbox in delphi 2012. The problem I'm running into is deserializing the json responses. When I make the request for a list of folders and files in my account I get a response that looks something like this:
{
"hash": "some_hash",
"thumb_exists": false,
"bytes": 0,
"path": "/",
"is_dir": true,
"size": "0 bytes",
"root": "dropbox",
"contents":
[
{
"revision": 11,
"rev": "b074cbcbb",
"thumb_exists": false,
"bytes": 0,
"modified": "Mon, 23 Apr 2012 19:19:27 +0000",
"path": "/Apps",
"is_dir": true,
"icon": "folder",
"root": "dropbox",
"size": "0 bytes"
},
{
"revision": 142,
"rev": "8e074cbcbb",
"thumb_exists": false,
"bytes": 0,
"modified": "Wed, 09 May 2012 22:55:44 +0000",
"path": "/code",
"is_dir": true,
"icon": "folder",
"root": "dropbox",
"size": "0 bytes"
},
{
"revision": 7,
"rev": "7074cbcbb",
"thumb_exists": false,
"bytes": 246000,
"modified": "Mon, 23 Apr 2012 18:40:51 +0000",
"client_mtime": "Mon, 23 Apr 2012 18:40:52 +0000",
"path": "/Getting Started.pdf",
"is_dir": false,
"icon": "page_white_acrobat",
"root": "dropbox",
"mime_type": "application/pdf",
"size": "240.2 KB"
}
],
"icon": "folder"
}
I would like to be able to parse that using a TJSONUnMarshal object, but it turns out that TJSONUnMarshal expects the json to look like this instead:
{
"type":"DropboxApiU.TFile",
"id":1,
"fields":
{
"hash": "some_hash",
"thumb_exists": false,
"bytes": 0,
"path": "/",
"is_dir": true,
"size": "0 bytes",
"root": "dropbox",
"contents":
[
{
"type":"DropboxApiU.TFile",
"id":1,
"fields":
{
"revision": 11,
"rev": "b074cbcbb",
"thumb_exists": false,
"bytes": 0,
"modified": "Mon, 23 Apr 2012 19:19:27 +0000",
"path": "/Apps",
"is_dir": true,
"icon": "folder",
"root": "dropbox",
"size": "0 bytes"
}
},
I've looked at this page and thought it might be what I'm looking for, but it never really goes into how to use a TTypeObjectReverter (which I think is what I need to use) and I can't seem to find an example online.
What would be the best way to make this happen? I'm hoping I can just write a TTypeObjectReverter, or something similar, but I would need to see a sample to be able to wrap my head around that.
edit Here's a screenshot of the differences between the two. The red is not sent in the response from the dropbox server, but is expected by the unmarshaler.