[wso2con eu 2017] manipulating xml, json and sql data types with ballerina

34
Associate Technical Lead, WSO2 Manipulating XML, JSON and SQL Data Types with Ballerina Shafreen Anfar

Upload: wso2-inc

Post on 21-Jan-2018

160 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

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

Let’s Begin With a Story!Time. Effort. Money.

Page 3: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

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

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

• 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

• 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

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

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
Page 10: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

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

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

Datatable

Page 13: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

• 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

XML

Page 15: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

• 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

XML in Ballerina : Constructs

Page 17: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

XML in Ballerina : Interpolation

Page 18: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

XML in Ballerina : Functions

Page 19: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

Back to the Story!

Page 20: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

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

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

• 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

A Developer’s Story

Sounds Like a Lot of Work!

Page 24: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

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

Business logic

Page 26: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

JSON

Page 27: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

• 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

JSON in Ballerina : Constructs

Page 29: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

JSON in Ballerina : Constructs

Page 30: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

JSON in Ballerina : Navigating

Page 31: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

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

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

A Developer’s Story

Page 34: [WSO2Con EU 2017] Manipulating XML, JSON and SQL Data Types with Ballerina

wso2.com