Notice: This Wiki is now read only and edits are no longer 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 the following JSON. For this example, we are only interested in the title and url fields of data/children/data.
{ "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 } }, ...
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 the following XML. For this example, we are only interested in the title and url fields of data/children/data.
Invalid language.
You need to specify a language like this: <source lang="html4strict">...</source>
Supported languages for syntax highlighting:
4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, arm, asm, asp, asymptote, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcl, dcpu16, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, freeswitch, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, haxe, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, ldif, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, nagios, netrexx, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, octave, oobas, oorexx, oracle11, oracle8, otj, oxygene, oz, parasail, parigp, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, pys60, python, q, qbasic, rails, rebol, reg, rexx, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, spark, sparql, sql, stonescript, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, upc, urbi, uscript, vala, vb, vbnet, vedit, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic
<?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:</p><p><a href="http://www.flickr.com/photos/d3capmode/8869663050/" title="Space Shuttle Endeavour"><img src="http://farm8.staticflickr.com/7366/8869663050_e0aa1331fe_m.jpg" width="240" height="114" alt="Space Shuttle Endeavour" /></a></p></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> ...