I'm trying use the Box 2.0 API which returns everything in JSON. This is great because I can use JSON.deserialize. I've run into one issue when getting the folder and file structure. Box returns it as an array of objects that can contain both files and folders. I'd like to have different Apex classes that represent files and folders, but can't figure out if it is possible to deserialize the JSON into these two different classes. The other option I have is to create a single class that is a superset of all fields. Here's a snippet of the JSON.
{"item_collection": {
"total_count": 2,
"entries": [
{
"type": "folder",
"id": "344470651",
"sequence_id": "0",
"etag": "0",
"name": "Signed and returned by you"
},
{
"type": "file",
"id": "2778062467",
"sequence_id": "0",
"etag": "0",
"sha1": "92da54134a52f3e264ab9ed346b3be95c9b2cdad",
"name": "Welcome.pdf"
}
]
}
Am I stuck doing the superset class or is there a way to get them split into separate classes?
Best Answer
Using the http://json2apex.herokuapp.com app developed by metadady and superfell was able to parse your JSON into apex class
Please try and it does magic .Thanks to metadady and Superfell and whoever built this app on herouku platform
Once we have the List of Entries(List entries)you can separated by using the Type in an another list .