|
|
(97 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | <div style="margin:5px;float:right;border:1px solid #000000;padding:5px">__TOC__</div>
| |
| | | |
− | =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:
| |
− |
| |
− | <code>
| |
− | http://www.reddit.com/r/science/top/.json?sort=top&t=day&limit=5
| |
− | </code>
| |
− |
| |
− | This will return us the following JSON. For this example, we are only interested in the '''title''' and '''url''' fields of '''data/children'''.
| |
− |
| |
− | {| style="font-size:70%; font-family:Courier" border="0" cellpadding="2"
| |
− | |- valign="top"
| |
− | | {
| |
− | "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
| |
− | }
| |
− | },
| |
− | ...
| |
− | |}
| |
− |
| |
− | <source lang="text">
| |
− | <div style="font-size:50%">
| |
− | {
| |
− | "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
| |
− | }
| |
− | },
| |
− | ...
| |
− | </div>
| |
− | </source>
| |