SlideShare a Scribd company logo
Jackson Beyond JSON:
Data format modules (XML, CSV)
Tatu Saloranta
@cowtowncoder
tatu@fasterxml.com
Beyond JSON: Modules
● Modules extend Jackson functionality
o Most new features outside core
o Data type modules for supporting Joda, Guava & more
o JAX-RS provider for using Jackson in Jersey (et al)
o Data formats (this talk) for XML, CSV & more
o Other modules
 Afterburner (code generation, +30% faster)
 Mr Bean (generate impls of interfaces)
 JSON Schema generator
 JAXB Annotation support
Beyond JSON: data formats
Extensions to Jackson that
o implement Streaming API, to expose token/event
streams for reading, token-based writing
o sometimes augmented at data-binding (XML)
o some use ‘format schema’ helper objects (CSV, Avro,
Protobuf)
o allow full range of data-binding (read <X> into POJOs,
write POJOs as <X>)
Beyond JSON: data formats
● Existing data format modules
o Binary JSON: Smile, BSON, CBOR
o JSON-like: MessagePack, YAML
o Textual: CSV, XML
o Binary: Avro, Protobuf (soon!)
● Level of support for processing models
o All support data-binding
o Most support tree model (XML only partial)
o All expose streaming (XML partial)
non-JSON: from DropWizard
Two main ways to use from DropWizard:
● JAX-RS Provider (implement
MessageBodyReader/-Writer):
○ JSON, XML, Smile/CBOR (binary JSON)
○ Simply add a Maven dep (or jar), will auto-register
● DIY
○ InputStream for reading
○ StreamingOutput for writing
○ Can also use with JSON
From DropWizard: automatic
When auto-registering, simply annotate end
points with @Produces, @Consumes…
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
… and things will “Just Work”
From DropWizard: DIY
public class Resource {
private final static ObjectMapper mapper = new ObjectMapper();
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path(“/stuff”)
public StreamingOutput getStuff(InputStream input) throws IOException {
RequestObject req = mapper.readValue(input, RequestObject.class);
final ResponseObject response = …;
return new StreamingOutput() {
public void write(OutputStream out) throws IOException {
mapper.writeValue(out, response);
}
};
// although most commonly, would wrap in ‘Response’ object
}
}
From DropWizard: DIY
Things to note on DIY:
● More work but also more control over
configuration, error handling
● StreamingOutput
o Good for streaming large responses
o Usually wrapped in `Response` (to control headers,
response codes)
● InputStream:
o Need to invoke Bean Validation manually
XML from DropWizard
Jackson XML module, JAX-RS provider:
https://github.com/FasterXML/jackson-dataformat-xml
https://github.com/FasterXML/jackson-jaxrs-providers
and optional JAXB annotation support
https://github.com/FasterXML/jackson-module-jaxb-
annotations
XML from DropWizard
● Due to auto-registration, not much to add
● XML-specific annotations:
o element vs attribute (Jackson / JAXB annotations)
o wrapper vs unwrapped lists
● Jackson vs JAXB
o Both work, viable alternatives
o Jackson has more powerful POJO handling
o JAXB supports “XML-centric” approach
o Beware of XML-providers’ “JSON solutions”
Jackson XML, DIY
If you want to do XML outside of DropWizard:
public class Person {
@JacksonXmlProperty(isAttribute=true)
public int age;
public String name;
}
XmlMapper mapper = new XmlMapper();
String xml = mapper.writeValueAsString(new Person(...));
=> <Person age=”25”>
<name>Jason Jackson</name>
</Person>
CSV from DropWizard
Jackson CSV module:
https://github.com/FasterXML/jackson-dataformat-csv
No JAX-RS provider yet (need to figure out how to provide
schema); may be added in future.
CSV is Different
Main differences from other formats:
1. Shallow 2-dimensional (tabular) structure
2. Positional (column 1, 2, …)
3. Only native data type String
So how to map to Jackson’s model, POJOs?
1. Handle as “raw” content (List<String[]>)
2. Use schema objects to map position->name
CSV usage, “untyped”
Simple “untyped” usage:
CsvMapper mapper = new CsvMapper();
// or: new ObjectMapper(new CsvFactory());
// read into String[][], or Object[]:
String[][] rows = mapper.readValue(
"1,xyzn2,abcn", String[][].class);
// write similarly; one of:
String csv = mapper.writeValueAsString(rows);
mapper.writeValue(new File(“output.csv”), rows);
CSV usage, “untyped”
// or stream through, for large documents
MappingIterator<String[]> it = mapper
.reader(String[].class)
.readValues(csv);
while (it.hasNext()) {
String[] row = it.nextValue();
// do something with it
}
CSV usage, POJOs
But to get to POJOs, we need CsvSchema:
● simple mapping between column positions, names
o manually:
CsvSchema schema = CsvSchema.builder().addColumn("firstName")
.addColumn("lastName").build()
o or from input (first row) -- see next slide
o or from Java class:
CsvSchema schema = mapper.schemaFor(Pojo.class);
● also contains doc properties: linefeed, column separator...
● NOT formal “CSV Schema”
CSV usage, POJOs
Typically as simple as:
Value[] values = mapper.readerWithSchemaFor(Value.class)
.readValue(new File(“input.csv”), Value[].class);
// or with MappingIterator
mapper.writer(mapper.schemaFor(Value.class)
.writeValue(new File(“output.csv”, values);
// or using 1st line as header for mapping
CsvSchema sch = CsvSchema.emptySchema().withHeader();
values = mapper.reader(Value.class).with(schema)
.readValue(source);
CSV: variations
Many variations:
● some CSV documents define column names in first row
(enable/disable via CsvSchema object)
● Different column separator (“TSV” for tab-delimited),
line separator
● Optional quoting, and/or escaping
● Null value to output (can not omit -- default “”)
● Settings part of CsvSchema object
Beyond JSON, take-away
Key takeaway: one tool, usage as close to
baseline of JSON as possible.
Some follow-up ideas:
● dynamic enabling of binary JSON (HTTP
format negotation)
● YAML for configuration (DropWizard
already uses Jackson YAML)
Beyond JSON, the End
That’s All, Folks! Questions?
Visit Jackson home at
https://github.com/FasterXML/jackson
and/or join mailing lists at
https://groups.google.com/forum/#!forum/jackson-user

More Related Content

What's hot

Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
Bala Narayanan
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
WebStackAcademy
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
Anjan Banda
 
C# Advanced L03-XML+LINQ to XML
C# Advanced L03-XML+LINQ to XMLC# Advanced L03-XML+LINQ to XML
C# Advanced L03-XML+LINQ to XML
Mohammad Shaker
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Automatically generating-json-from-java-objects-java-objects268
Automatically generating-json-from-java-objects-java-objects268Automatically generating-json-from-java-objects-java-objects268
Automatically generating-json-from-java-objects-java-objects268Ramamohan Chokkam
 
Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)
Sumant Tambe
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scala
Ruslan Shevchenko
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
Walid Ashraf
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
Mindfire Solutions
 
JavaScript objects and functions
JavaScript objects and functionsJavaScript objects and functions
JavaScript objects and functions
Victor Verhaagen
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Ramamohan Chokkam
 
3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOM
Jalpesh Vasa
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 

What's hot (20)

Ajax
AjaxAjax
Ajax
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
C# Advanced L03-XML+LINQ to XML
C# Advanced L03-XML+LINQ to XMLC# Advanced L03-XML+LINQ to XML
C# Advanced L03-XML+LINQ to XML
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Automatically generating-json-from-java-objects-java-objects268
Automatically generating-json-from-java-objects-java-objects268Automatically generating-json-from-java-objects-java-objects268
Automatically generating-json-from-java-objects-java-objects268
 
Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)
 
Week3
Week3Week3
Week3
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scala
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
Json the-x-in-ajax1588
Json the-x-in-ajax1588Json the-x-in-ajax1588
Json the-x-in-ajax1588
 
JavaScript objects and functions
JavaScript objects and functionsJavaScript objects and functions
JavaScript objects and functions
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
 
3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOM
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 

Viewers also liked

オブジェクト指向っぽい話
オブジェクト指向っぽい話オブジェクト指向っぽい話
オブジェクト指向っぽい話
Tomohiro Shinden
 
Officeで使うPerl Excel編
Officeで使うPerl Excel編Officeで使うPerl Excel編
Officeで使うPerl Excel編
risou
 
Perl 6 Object-Oliented Programming
Perl 6 Object-Oliented ProgrammingPerl 6 Object-Oliented Programming
Perl 6 Object-Oliented Programming
risou
 
北斗の拳の世界をオブジェクト指向で
北斗の拳の世界をオブジェクト指向で北斗の拳の世界をオブジェクト指向で
北斗の拳の世界をオブジェクト指向でyaju88
 
エクストリームエンジニア5
エクストリームエンジニア5エクストリームエンジニア5
エクストリームエンジニア5
T-arts
 
第2回勉強会 オブジェクト指向
第2回勉強会 オブジェクト指向第2回勉強会 オブジェクト指向
第2回勉強会 オブジェクト指向
hakoika-itwg
 
第3回勉強会 オブジェクト指向
第3回勉強会 オブジェクト指向第3回勉強会 オブジェクト指向
第3回勉強会 オブジェクト指向
hakoika-itwg
 

Viewers also liked (7)

オブジェクト指向っぽい話
オブジェクト指向っぽい話オブジェクト指向っぽい話
オブジェクト指向っぽい話
 
Officeで使うPerl Excel編
Officeで使うPerl Excel編Officeで使うPerl Excel編
Officeで使うPerl Excel編
 
Perl 6 Object-Oliented Programming
Perl 6 Object-Oliented ProgrammingPerl 6 Object-Oliented Programming
Perl 6 Object-Oliented Programming
 
北斗の拳の世界をオブジェクト指向で
北斗の拳の世界をオブジェクト指向で北斗の拳の世界をオブジェクト指向で
北斗の拳の世界をオブジェクト指向で
 
エクストリームエンジニア5
エクストリームエンジニア5エクストリームエンジニア5
エクストリームエンジニア5
 
第2回勉強会 オブジェクト指向
第2回勉強会 オブジェクト指向第2回勉強会 オブジェクト指向
第2回勉強会 オブジェクト指向
 
第3回勉強会 オブジェクト指向
第3回勉強会 オブジェクト指向第3回勉強会 オブジェクト指向
第3回勉強会 オブジェクト指向
 

Similar to Jackson beyond JSON: XML, CSV

Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
Łukasz Bałamut
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
Json generation
Json generationJson generation
Json generation
Aravindharamanan S
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problemstitanlambda
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorialKat Roque
 
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemWprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Sages
 
Text processing by Rj
Text processing by RjText processing by Rj
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript Workshop
Pamela Fox
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Vitaly Gordon
 
JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2
Laurence Svekis ✔
 
Cascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUGCascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUG
Matthew McCullough
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
antoinegirbal
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
antoinegirbal
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
Simon Willison
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
Scripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScript
Justin Deoliveira
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
Beau Lebens
 

Similar to Jackson beyond JSON: XML, CSV (20)

Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Json generation
Json generationJson generation
Json generation
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemWprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
 
Text processing by Rj
Text processing by RjText processing by Rj
Text processing by Rj
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript Workshop
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
 
JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2
 
Cascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUGCascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUG
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Scripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScript
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 

Recently uploaded

Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 

Recently uploaded (20)

Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 

Jackson beyond JSON: XML, CSV

  • 1. Jackson Beyond JSON: Data format modules (XML, CSV) Tatu Saloranta @cowtowncoder tatu@fasterxml.com
  • 2. Beyond JSON: Modules ● Modules extend Jackson functionality o Most new features outside core o Data type modules for supporting Joda, Guava & more o JAX-RS provider for using Jackson in Jersey (et al) o Data formats (this talk) for XML, CSV & more o Other modules  Afterburner (code generation, +30% faster)  Mr Bean (generate impls of interfaces)  JSON Schema generator  JAXB Annotation support
  • 3. Beyond JSON: data formats Extensions to Jackson that o implement Streaming API, to expose token/event streams for reading, token-based writing o sometimes augmented at data-binding (XML) o some use ‘format schema’ helper objects (CSV, Avro, Protobuf) o allow full range of data-binding (read <X> into POJOs, write POJOs as <X>)
  • 4. Beyond JSON: data formats ● Existing data format modules o Binary JSON: Smile, BSON, CBOR o JSON-like: MessagePack, YAML o Textual: CSV, XML o Binary: Avro, Protobuf (soon!) ● Level of support for processing models o All support data-binding o Most support tree model (XML only partial) o All expose streaming (XML partial)
  • 5. non-JSON: from DropWizard Two main ways to use from DropWizard: ● JAX-RS Provider (implement MessageBodyReader/-Writer): ○ JSON, XML, Smile/CBOR (binary JSON) ○ Simply add a Maven dep (or jar), will auto-register ● DIY ○ InputStream for reading ○ StreamingOutput for writing ○ Can also use with JSON
  • 6. From DropWizard: automatic When auto-registering, simply annotate end points with @Produces, @Consumes… @Produces(MediaType.APPLICATION_XML) @Consumes(MediaType.APPLICATION_XML) … and things will “Just Work”
  • 7. From DropWizard: DIY public class Resource { private final static ObjectMapper mapper = new ObjectMapper(); @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path(“/stuff”) public StreamingOutput getStuff(InputStream input) throws IOException { RequestObject req = mapper.readValue(input, RequestObject.class); final ResponseObject response = …; return new StreamingOutput() { public void write(OutputStream out) throws IOException { mapper.writeValue(out, response); } }; // although most commonly, would wrap in ‘Response’ object } }
  • 8. From DropWizard: DIY Things to note on DIY: ● More work but also more control over configuration, error handling ● StreamingOutput o Good for streaming large responses o Usually wrapped in `Response` (to control headers, response codes) ● InputStream: o Need to invoke Bean Validation manually
  • 9. XML from DropWizard Jackson XML module, JAX-RS provider: https://github.com/FasterXML/jackson-dataformat-xml https://github.com/FasterXML/jackson-jaxrs-providers and optional JAXB annotation support https://github.com/FasterXML/jackson-module-jaxb- annotations
  • 10. XML from DropWizard ● Due to auto-registration, not much to add ● XML-specific annotations: o element vs attribute (Jackson / JAXB annotations) o wrapper vs unwrapped lists ● Jackson vs JAXB o Both work, viable alternatives o Jackson has more powerful POJO handling o JAXB supports “XML-centric” approach o Beware of XML-providers’ “JSON solutions”
  • 11. Jackson XML, DIY If you want to do XML outside of DropWizard: public class Person { @JacksonXmlProperty(isAttribute=true) public int age; public String name; } XmlMapper mapper = new XmlMapper(); String xml = mapper.writeValueAsString(new Person(...)); => <Person age=”25”> <name>Jason Jackson</name> </Person>
  • 12. CSV from DropWizard Jackson CSV module: https://github.com/FasterXML/jackson-dataformat-csv No JAX-RS provider yet (need to figure out how to provide schema); may be added in future.
  • 13. CSV is Different Main differences from other formats: 1. Shallow 2-dimensional (tabular) structure 2. Positional (column 1, 2, …) 3. Only native data type String So how to map to Jackson’s model, POJOs? 1. Handle as “raw” content (List<String[]>) 2. Use schema objects to map position->name
  • 14. CSV usage, “untyped” Simple “untyped” usage: CsvMapper mapper = new CsvMapper(); // or: new ObjectMapper(new CsvFactory()); // read into String[][], or Object[]: String[][] rows = mapper.readValue( "1,xyzn2,abcn", String[][].class); // write similarly; one of: String csv = mapper.writeValueAsString(rows); mapper.writeValue(new File(“output.csv”), rows);
  • 15. CSV usage, “untyped” // or stream through, for large documents MappingIterator<String[]> it = mapper .reader(String[].class) .readValues(csv); while (it.hasNext()) { String[] row = it.nextValue(); // do something with it }
  • 16. CSV usage, POJOs But to get to POJOs, we need CsvSchema: ● simple mapping between column positions, names o manually: CsvSchema schema = CsvSchema.builder().addColumn("firstName") .addColumn("lastName").build() o or from input (first row) -- see next slide o or from Java class: CsvSchema schema = mapper.schemaFor(Pojo.class); ● also contains doc properties: linefeed, column separator... ● NOT formal “CSV Schema”
  • 17. CSV usage, POJOs Typically as simple as: Value[] values = mapper.readerWithSchemaFor(Value.class) .readValue(new File(“input.csv”), Value[].class); // or with MappingIterator mapper.writer(mapper.schemaFor(Value.class) .writeValue(new File(“output.csv”, values); // or using 1st line as header for mapping CsvSchema sch = CsvSchema.emptySchema().withHeader(); values = mapper.reader(Value.class).with(schema) .readValue(source);
  • 18. CSV: variations Many variations: ● some CSV documents define column names in first row (enable/disable via CsvSchema object) ● Different column separator (“TSV” for tab-delimited), line separator ● Optional quoting, and/or escaping ● Null value to output (can not omit -- default “”) ● Settings part of CsvSchema object
  • 19. Beyond JSON, take-away Key takeaway: one tool, usage as close to baseline of JSON as possible. Some follow-up ideas: ● dynamic enabling of binary JSON (HTTP format negotation) ● YAML for configuration (DropWizard already uses Jackson YAML)
  • 20. Beyond JSON, the End That’s All, Folks! Questions? Visit Jackson home at https://github.com/FasterXML/jackson and/or join mailing lists at https://groups.google.com/forum/#!forum/jackson-user