Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
User:Rick.barkhouse.oracle.com/Test1
Dynamic JAXB: Flickr Example
This example will demonstrate how to use MOXy's Dynamic JAXB features to work with public JSON and XML feeds, without having to create concrete Java classes.
Getting JSON from Reddit
Reddit provides a public JSON feed using the following URL format:
http://www.reddit.com/r/science/top/.json?sort=top&t=day&limit=5
This will return us JSON in the following format. For this example, we are primarily interested in the title and url fields of data/children/data.
Mapping to Reddit JSON
The metadata that defines our mappings to the JSON output is stored in the
Getting XML from Flickr
Flickr provides a public XML feed using the following URL format:
http://api.flickr.com/services/feeds/photos_public.gne?tags=science
This will return us XML in the following format. For this example, we want to locate the entry/link element who has @type='image/jpeg, and grab the href attribute, pointing to the actual image.
Appendix - Data Formats
Reddit JSON Format
{ "kind":"Listing", "data":{ "modhash":"qdohhwkxss9091dc13eed91db333b619420a787aa2a39b3982", "children":[ { "kind":"t3", "data":{ "domain":"news.mongabay.com", "banned_by":null, "media_embed":{ }, "subreddit":"science", "selftext_html":null, "selftext":"", "likes":null, "link_flair_text":null, "id":"1f5jv3", "clicked":false, "title":"Plants re-grow after 500 years under the ice", "media":null, "score":2665, "approved_by":null, "over_18":false, "hidden":false, "thumbnail":"", "subreddit_id":"t5_mouw", "edited":false, "link_flair_css_class":null, "author_flair_css_class":null, "downs":5569, "saved":false, "is_self":false, "permalink":"/r/science/comments/1f5jv3/plants_regrow_after_500_years_under_the_ice/", "name":"t3_1f5jv3", "created":1369712639.0, "url":"http://news.mongabay.com/2013/0527-dimitrova-ice-plants.html", "author_flair_text":null, "author":"soyuz-capsule", "created_utc":1369683839.0, "ups":8234, "num_comments":178, "num_reports":null, "distinguished":null } }, ...
Flickr XML Format
<?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:flickr="urn:flickr:user" xmlns:media="http://search.yahoo.com/mrss/"> <title>Recent Uploads tagged science</title> <link rel="self" href="http://api.flickr.com/services/feeds/photos_public.gne?tags=science" /> <link rel="alternate" type="text/html" href="http://www.flickr.com/photos/tags/science/" /> <id>tag:flickr.com,2005:/photos/public/tagged/all/science</id> <icon>http://l.yimg.com/g/images/buddyicon.gif</icon> <subtitle /> <updated>2013-05-28T17:54:28Z</updated> <generator uri="http://www.flickr.com/">Flickr</generator> <entry> <title>Space Shuttle Endeavour</title> <link rel="alternate" type="text/html" href="http://www.flickr.com/photos/d3capmode/8869663050/" /> <id>tag:flickr.com,2005:/photo/8869663050</id> <published>2013-05-28T17:54:28Z</published> <updated>2013-05-28T17:54:28Z</updated> <flickr:date_taken>2013-05-26T14:11:25-08:00</flickr:date_taken> <dc:date.Taken>2013-05-26T14:11:25-08:00</dc:date.Taken> <content type="html"><p><a href="http://www.flickr.com/people/d3capmode/">Jason Scheier</a> posted a photo:</content> <author> <name>Jason Scheier</name> <uri>http://www.flickr.com/people/d3capmode/</uri> <flickr:nsid>49842342@N07</flickr:nsid> <flickr:buddyicon>http://farm6.staticflickr.com/5452/buddyicons/49842342@N07.jpg?1369198532#49842342@N07</flickr:buddyicon> </author> <link rel="enclosure" type="image/jpeg" href="http://farm8.staticflickr.com/7366/8869663050_e0aa1331fe_b.jpg" /> <category term="park" scheme="http://www.flickr.com/photos/tags/" /> <category term="love" scheme="http://www.flickr.com/photos/tags/" /> <category term="los" scheme="http://www.flickr.com/photos/tags/" /> <category term="memorial" scheme="http://www.flickr.com/photos/tags/" /> <category term="day" scheme="http://www.flickr.com/photos/tags/" /> <category term="control" scheme="http://www.flickr.com/photos/tags/" /> <category term="angeles" scheme="http://www.flickr.com/photos/tags/" /> <category term="space" scheme="http://www.flickr.com/photos/tags/" /> <category term="engineering" scheme="http://www.flickr.com/photos/tags/" /> <category term="center" scheme="http://www.flickr.com/photos/tags/" /> <category term="science" scheme="http://www.flickr.com/photos/tags/" /> <category term="nasa" scheme="http://www.flickr.com/photos/tags/" /> <category term="exposition" scheme="http://www.flickr.com/photos/tags/" /> <category term="shuttle" scheme="http://www.flickr.com/photos/tags/" /> <category term="mission" scheme="http://www.flickr.com/photos/tags/" /> <category term="jpl" scheme="http://www.flickr.com/photos/tags/" /> <category term="starship" scheme="http://www.flickr.com/photos/tags/" /> <category term="endeavour" scheme="http://www.flickr.com/photos/tags/" /> </entry> <entry> ...