[WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina
-
Upload
wso2-inc -
Category
Technology
-
view
161 -
download
0
Transcript of [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina
![Page 1: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/1.jpg)
Associate Technical Lead, WSO2
Manipulating XML, JSON and SQL Data Types with Ballerina
Shafreen Anfar
![Page 2: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/2.jpg)
Let’s Begin With a Story!Time. Effort. Money.
![Page 3: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/3.jpg)
A Developer’s Story
James (CEO of DataDump Inc.)
William (Conservative, butworking hard)
Henry(Open-minded andworking smart)
![Page 4: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/4.jpg)
James wants his developers to develop a REST service that exposes employee data of his company as a service.
James: Oh! I also want the resource representation to be XML.
A Developer’s Story
![Page 5: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/5.jpg)
• Willam’s approach– Chose Java– Decide on a JAX-RS implementation – Decide on a suitable XML library– Extract data from the database
A Developer’s Story
![Page 6: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/6.jpg)
• Willam’s approach– Using XML library, convert it into
XML– Set it as the response of the service – Deploy it on some web container
A Developer’s Story
![Page 7: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/7.jpg)
Not anymore!Thanks to Ballerina, things are different now.
A Developer’s Story Sounds Complex?
![Page 8: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/8.jpg)
Henry, chose Ballerina and Bob is his uncle!
A Developer’s Story
![Page 9: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/9.jpg)
![Page 10: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/10.jpg)
Henry’s code is not only simple, but also gets the Job done effectively.
A Developer’s Story
![Page 11: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/11.jpg)
Simplicity is something we strive to achieve in Ballerina.
“Simplicity is the ultimateSophistication” - Leonardo da Vinci
A Developer’s Story
![Page 12: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/12.jpg)
Datatable
![Page 13: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/13.jpg)
• Ballerina natively supports handling tabular data structures
• Datatable can be casted to a struct, XML or JSON• Supports data streaming• Work in progress
– Letting users populate datatables and directly write to the DB.
Datatable in Ballerina
![Page 14: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/14.jpg)
XML
![Page 15: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/15.jpg)
• No Need to Worry About Third-Party Libraries!• XML is part of the type system of Ballerina• Provides compile time validation• Ballerina has its extended version of XML spec
– James Clark (https://en.wikipedia.org/wiki/James_Clark_(programmer))
XML in Ballerina
![Page 16: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/16.jpg)
XML in Ballerina : Constructs
![Page 17: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/17.jpg)
XML in Ballerina : Interpolation
![Page 18: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/18.jpg)
XML in Ballerina : Functions
![Page 19: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/19.jpg)
Back to the Story!
![Page 20: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/20.jpg)
Now, James wants William and Henry to develop another service to see which employees are eligible for awards for the current quarter.
But this time James wants it to be mobile friendly.
A Developer’s Story
![Page 21: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/21.jpg)
William goes back to the whiteboard and start designing!
A Developer’s Story
![Page 22: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/22.jpg)
• Decide on a JSON implementation • Use the previously used XML library and
construct payload from the response stream• Do the logic to get the list of eligible
employees• Serialize the XML payload to JSON
A Developer’s Story
![Page 23: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/23.jpg)
A Developer’s Story
Sounds Like a Lot of Work!
![Page 24: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/24.jpg)
Once again, Henry chose Ballerina and Bob is his uncle!
A Developer’s Story
![Page 25: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/25.jpg)
Business logic
![Page 26: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/26.jpg)
JSON
![Page 27: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/27.jpg)
• No need to worry about third-party libraries• JSON is part of the type system of Ballerina• Provides compile time validation• Can easily add, remove, modify• Constrained JSON provides extra validation• Similar to maps and structs in Ballerina
JSON in Ballerina
![Page 28: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/28.jpg)
JSON in Ballerina : Constructs
![Page 29: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/29.jpg)
JSON in Ballerina : Constructs
![Page 30: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/30.jpg)
JSON in Ballerina : Navigating
![Page 31: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/31.jpg)
A Developer’s Story
Who’s the Smarter and Happier DeveloperNow?
![Page 32: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/32.jpg)
Henry, the Ballerina developer ... – Can focus on the exact requirement– Saves time and effort– Ultimately saves money– Writes simple and readable code
A Developer’s Story
![Page 33: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6490f47f8b9a2c568b5c57/html5/thumbnails/33.jpg)
A Developer’s Story