Java Reference
In-Depth Information
BadgerFish is kind of unnatural when writing JavaScript, but if you want to unify your
formats under XML schema, it's the way to go.
JSON and JSON Schema
The thing with using XML schema and the BadgerFish mapping to define your JSON data
structures is that it is very weird for JavaScript programmers to consume. If you do not need
to support XML clients or if you want to provide a cleaner and simpler JSON representation,
there are some options available for you.
It doesn't make much sense to use XML schema to define JSON data structures. The main
reason is that JSON is a richer data format that supports things like maps, lists, and numeric,
Boolean, and string data. It is a bit quirky modeling these sorts of simple data structures with
XML schema. To solve this problem, the JSON community has come up with JSON schema.
Here's an example of what it looks like when you define a JSON data structure representing
our customer example:
"description" : "A customer" ,
"type" : "object" ,
"properties" :
{ "first"
"first" : { "type"
"type" : "string" },
"last" : { "type"
"type" : "string" }
The description property defines the description for the schema. The type property
defines what is being described. Next, you define a list of properties that make up your ob-
ject. I won't go into a lot of detail about JSON schema, so you should visit http://www.json- to get more information on this subject.
If you do a Google search on Java and JSON, you'll find a plethora of frameworks that help
you marshal and unmarshal between Java and JSON. One particularly good one is the Jack-
son [ 6 ] framework. It has a prewritten JAX-RS content handler that can automatically convert
Java beans to and from JSON. It can also generate JSON schema documents from a Java ob-
ject model.
The way it works by default is that it introspects your Java class, looking for properties, and
maps them into JSON. For example, if we had the Java class:
public class
class Customer
Customer {
private int
int id ;
private String firstName ;
Search WWH ::

Custom Search