Created
June 30, 2015 08:14
-
-
Save Sunil02kumar/f73f5632bb2ce9a40971 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
JSON String: | |
{ | |
"type":"session", | |
"id":"d1425e031062455f909740bb770b95a7", | |
"document":{ | |
"type":"document", | |
"id":"ab0dc2d377524f44a98fd1476343637e", | |
"status":"processing", | |
"name":"", | |
"created_at":"2015-06-19T08:35:09Z" | |
}, | |
"expires_at":"2015-06-19T09:35:10.020Z", | |
"urls":{ | |
"view":"https://view-api.box.com/1/sessions/d1425e031062455f909740bb770b95a7/view", | |
"assets":"https://view-api.box.com/1/sessions/d1425e031062455f909740bb770b95a7/assets/", | |
"realtime":"https://view-api.box.com/sse/d1425e031062455f909740bb770b95a7" | |
} | |
} | |
*/ | |
public class JSON2Apex { | |
public class Document { | |
public String type; | |
public String id; | |
public String status; | |
public String name; | |
public String created_at; | |
} | |
public class Urls { | |
public String view; | |
public String assets; | |
public String realtime; | |
} | |
public String type; | |
public String id; | |
public Document document; | |
public String expires_at; | |
public Urls urls; | |
public static JSON2Apex parse(String json) { | |
return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class); | |
} | |
static testMethod void testParse() { | |
String json = '{ '+ | |
' \"type\":\"session\",'+ | |
' \"id\":\"d1425e031062455f909740bb770b95a7\",'+ | |
' \"document\":{ '+ | |
' \"type\":\"document\",'+ | |
' \"id\":\"ab0dc2d377524f44a98fd1476343637e\",'+ | |
' \"status\":\"processing\",'+ | |
' \"name\":\"\",'+ | |
' \"created_at\":\"2015-06-19T08:35:09Z\"'+ | |
' },'+ | |
' \"expires_at\":\"2015-06-19T09:35:10.020Z\",'+ | |
' \"urls\":{ '+ | |
' \"view\":\"https://view-api.box.com/1/sessions/d1425e031062455f909740bb770b95a7/view\",'+ | |
' \"assets\":\"https://view-api.box.com/1/sessions/d1425e031062455f909740bb770b95a7/assets/\",'+ | |
' \"realtime\":\"https://view-api.box.com/sse/d1425e031062455f909740bb770b95a7\"'+ | |
' }'+ | |
'}'; | |
JSON2Apex obj = parse(json); | |
System.assert(obj != null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment