Tuesday Mar 25, 2014

Java API for JSON Processing (JSR 353)

Computer programs are the most complex things that humans make.” (Douglas Crockford)

JSON (JavaScript Object Notation) is a widely used, lightweight, simple data-interchange format. JSON is not so new but there is, since a few months, a formal ECMA standardising JSON: "ECMA 404 - The JSON Data Interchange Format". ECMA 404 is probably the sweetest and easiest specification to read and grasp! The document is 14 pages long but if you remove all the decorations, the specification itself is not even 7 pages long!

Java API for JSON Processing (JSR 353) is one of the 4 new APIs added to Java EE 7 alongs with the Batch API (JSR 352), the WeSocket API (JSR 356) and the Concurrency Utilities for Java EE API (JSR 236). JSR 353 provides an API to parse, transform, and query JSON data using the object model or the streaming mode.

Java has a long history of various JSON APIs but the value of JSON-P (JSR 353) is the fact that it has been standardised. That means that we can expect this API to work seamlessly on any Java EE 7 implementations, i.e. GlassFish 4, JEUS 8 and WildFly 8 today. And this is juts the beginning, we can also expect the adoption of JSON-P API to rapidly grow. For example, the upcoming WebLogic 12.1.3 will add support for various Java EE 7 APIs including JSON-P, see here.

It should be mentioned that binding is not yet covered by this specification but JSON-B is high on the wish-list for Java EE 8.

To know more about JSON-P, you can read the JSON-P chapter of the Java EE 7 Tutorial or watch the 'JSR 353: JSON Processing API in Action' session from last JavaOne.

Thursday Aug 08, 2013

An Overview of JSON-P

JSON is quickly becoming the de facto data interchange format on the web, especially with powerful JavaScript clients, Ajax, REST and HTML 5 WebSockets. This is why JSON-P (or more formally the Java API for JSON Processing) is such a key part of the Java EE 7 release. It is intended to provide a standard, vendor-neutral, ubiquitous solution for parsing, generating and querying JSON. In a brief OTN article, JSON-P specification lead Jitendra Kotamraju (or Jitu as he prefers to be called) overviews JSON-P. He discusses the basics of JSON, JSON-P, the DOM-like Object Model API and the StAX-like Streaming API. There's also the 20-minute JSON-P presentation on the GlassFish videos YouTube channel and my own slide deck below:

You can also check out the very well written JSON-P section of the official Java EE 7 Tutorial or try things out with the newly released Java EE 7 SDK.

Thursday Jun 28, 2012

EclipseLink 2.4 Released: RESTful Persistence, Tenant Isolation, NoSQL, and JSON

EclipseLink 2.4 is released as part of Eclipse Juno release train. In addition to providing the Reference Implementation for JPA 2.0, the key features in the release are:

  • RESTful Persistence - Expose Java Persistence units over REST using either JSON or XML
  • Tenant Isolation - Manage entities for multiple tenants in the same application
  • NoSQL - NoSQL support for MongoDB and Oracle NoSQL
  • JSON - Marshaling and unmarshaling of JSON object
Eclipse Link 2.4

Here is the complete list of bugs fixed in this release. The landing page provide the complete list of documentation and examples. Read Doug Clarke's blog for a color commentary as well.

This release is already integrated in the latest GlassFish 4.0 promoted build.

Try the functionality and give us feedback at GlassFish Forum or EclipseLink Forum.

Friday Jan 06, 2012

Tab Sweep - JSON, OSGi, GlassFish+NetBeans experience, JAXB and JodaTime, file uploads & more

Recent Tips and News on Java, Java EE 6, GlassFish & more :

Radio Receiver

JSON to Java with JDK6 (Julien)
What does the future hold for OSGi without leader Peter Kriens? (JAXenter)
JavaCloudGuy: Glassfish (Java EE 6) is now available as option in #cumulogic (Twitter)
JAXB and Joda-Time: Dates and Times (Blaise)
JAX-RS Tip of the Day: Using YUI2 and YUI3 DataTables with Jersey and jQuery (John)
JAX-RS @MatrixParam example (mkyong)
First experiences and getting started with GlassFish 3.1 and NetBeans 7.x – it’s a breeze (Lucas)
Maven's WAR Overlay: What are WAR Overlays? (DZone)
Book Review for "Java EE 6 with GlassFish Application Server" (Rick)
Managing unmanaged beans in CDI (Nicolas)
Using Bean Validation together with ExtVal in JPA and JSF (Edwin)
Java EE 6 using WebLogic 12c and NetBeans (Video) (Arun)
Spark, A micro Web Framework (spark.com)
Multiple File Upload Examples (John Yeary)
Released: NetBeans Platform 7, The Book (Geertjan)
Java 7: Understanding the Phaser (Niklas)
Where's my log file? (Nigel @ Open Messaging)
Sample: Java EE 6 + Wicket + NetBeans + GlassFish + MySQL (Geertjan)
Using Jsp in a Jersey JAX-RS RESTful application (François)
How to change the Glassfish server log level from command line (François)

JSON JSR is a GO

With 10 YES votes, another candidate Java EE 7 JSR has been accepted by the JCP Executive Committee: JSR 353, Java API for JSON Processing.

If you can't wait for the final version (currently scheduled for Q3 2012) and further integration with JavaSE, you may find Julien Viet's recent post to be of interest.

ALT_DESCR

Wednesday Dec 07, 2011

Lesser-advertised Java EE.next JSRs

As you may have already read here, Java EE 7 (JSR 342) is well on its way with some JSRs having reached the early draft status (e.g. JAX-RS 2.0, JSF 2.2, CDI 1.1, ...).

ALT_DESCR

On the other hand, you may not have heard of the following JSRs that are all candidates for inclusion in the Java EE Platform:
State Management (JSR 350) was recently filed by Oracle to offer a standard API for a state management subsystem (examples of state include HTTPSession and any state associated with CDI scoping annotations).
Batch (JSR 352) was covered here just recently as it has recently passed the Review Ballot.
Concurrency Utilities for Java EE (JSR 236) is building on JSR-166 (java.util.concurrency) to provide a clean abstraction for threaded code in a managed environment. It has been ongoing for several years and should be revived and completed in time for Java EE 7.
Java API for JSON Processing (JSR 353) is a parsing API for manipulating (reading or writing) JSON content. Binding (JAXB-style) is not in the scope of this newly submitted JSR.

The exact list of JSRs that will be part of Java EE 7 is up to the expert group to decide. Arun has more details on the status of each JSR.

Tuesday Oct 28, 2008

... JSON with Jersey, JSF with NB and GMaps, Comet, GF ESB and Fuji M2, Andy, iPhone and Oprah

A compilation of today's news of interest:

Radio Receiver Icon

Jakub has published a new Enterprise Tip on Jersey showing how to Configure JSON for RESTful Web Services in Jersey 1.0. Jersey is the production-quality, reference implementation of JAX-RS, the JCP standard for RESTful Web Services. JAX-RS is part of Java EE 6, but it can also be used separately. Jersey is part of GFv3 Prelude.

On JSF - first the NetBeans team shows how to Start Developing JSF Applications with the new NetBeans releases, including the forthcoming NB 6.5. Then Arun shows how to use JSF and Google Maps using Gmaps4JSF, Facelets and Mojarra on GlassFish v3 Prelude.

Comet and Atmosphere - JFA recently presented on Atmosphere - his new portable Comet framework - at the Silicon Valley JUG. The slides are Now Available.

GlassFish ESB is getting very close to its first Release Candidate (and GA/FCS release) (Milestone 2 Download) but I just noticed I had not spotlighted Mike's excellent Screencast on GlassFish ESB. Check it out and notice it is a multi-parter - very well done.

While we await GF ESB v2, we are already working on the next generation, which is based on Project Fuji. Fuji Milestone 2 released last week, and here are two additional posts: Nikki on Interceptors in Fuji and Derek on the Proxy bundle.

Andy B is adjusting his time involvement at Sun so he can spend more time with Arista Networks, "one of his startup companies" that is focused on the 10 Gigabit Ethernet switching business. The Original NYTimes Article was followed by a Clarification.

And today's toys includes Google Earth on iPhone, and Oprah endorses Kindle. Of the two, I think Oprah's endorsement will have the largest impact - is the time for the electronic reader finally here?

NB. I am a few days behind in reporting news; I'll try to catch up in the next day or two.

Thursday Feb 28, 2008

Better JSON in Jersey, jMaki included

ALT DESCR

JSON (JSON@TA) is a key component in Ajax and a REST framework like Jersey needs to support it well to be successful. Jakub reports on a new simpler default JSON data format in the latest Jersey; check his Description of Features and then see its use in jMaki Widgets.

Check it out and let Jakub, Paul and Marc know how it works for you.

Jersey's latest release is 0.6ea and is available from the Jersey Downloads Page. The latest stable release is 0.5ea and is also available through the Update Center. Jersey 0.6ea will be pushed to the UC in about 10 days.

Sunday Oct 07, 2007

How to consume Jersey resource representations in jMaki ?

Informational Sign

A tip on jMaki and Jersey working together:

How to consume JSON and XML representations generated by Jersey in jMaki ?

Friday Sep 14, 2007

Arun's TOTD Series - Tips on Metro, jMaki and more...

Headshot of Arun

Arun has started a TOTD (Tip of the Day) Series covering jRuby, jMaki, Metro, GlassFish and more. The entries are usually very detailed and focused on specific tasks.

You can get the whole stream as an RSS Feed. The last 5 entries are:

Using JDBC connection pool/JNDI name from GlassFish in Rails Application,
Generating JSON using JAXB and Jersey
Switch between jRuby and cRuby in NetBeans
Difference betwen Ruby Gems and Plugins
Loading Data from Beans in jMaki Widgets

We will try to give you heads-up of new additions via quick Tips.

Tuesday Sep 04, 2007

JSR 311 vs. Jersey vs. SWDP vs. GlassFish vs. NetBeans

Island of Jersey

If you're new to JAX-RS (JSR 311) and RESTful Web Service with Java, wondering how it impacts you as a developer, you should read this introduction to the various Sun efforts in that space.

If you're tracking the progress of Jersey, the JAX-RS Reference Implementation, you'll probably interested to hear that version 0.2.1 has been released today with a documented list of required JAR dependencies, illustrated in this demo showing how JAXB beans can be serialized as JSON or XML depending on the Accept HTTP header).

At this point, installing in GlassFish is fairly easy with a jersey-on-glassfish.xml ANT script. It'll get even easier once Jersey is made available on the GlassFish Update Center. Any day now I hear ;)

Tuesday Aug 07, 2007

JSON Encoding - Now in Jersey too

Encoder

Paul added support for pluggable type system in Jersey. All the supported types need to implement the EntityProvider interface and are registered in the META-INF/services file javax.ws.rs.ext.EntityProvider. Jakub used that system to add support for JSON encoding. Jersey is the GlassFish project that is implementing JAX-RS

The JSON binding in JAX-RS enables to use application/json as the MIME type and specify JSONArray, JSONObject as method parameters and return type. The JSON binding in JAX-RS enables to write code like the following:

@UriTemplate("/rates")
public class ExchangeRates {
    @ProduceMime("application/json")
    @UriTemplate("CZK")
    public JSONObject getRates() {
        try {
            return new JSONObject()
            .put("USD", 20.04);
        } catch (JSONException ex) {
            throw new WebApplicationException(ex);
        }
    }
}

JAX-WS takes advantage of a similar pluggable encoding layer in their implementation to provide a JSON binding.

Saturday Apr 28, 2007

Improved JSON Support

More improvements to the JSON support in GlassFish. Kohsuke reports on progress in the client-side programming model, including a new, JavaScript-centric tool in the spirit of wsimport).

The JavaScript client can then just include the proxy script and then asynchronously invoke the WS service as follows:

<script src="path/to/endpoint?js"></script> myService.get( {id:5}, function(r) { alert("ID="+r.id); alert("title="+r.title); } );

Screenshot of generated documentation

The JSON extension exploits the Schema analysis machinery in JAX-WS which means that it can generate nice JavaScript and can also do things like generating very nice looking documentation automatically - as shown (somewhat washed out) at left.

JSON support is in the "and more..." portion of Kohsuke and Jitu's presentation at JavaOne: TS-4948 "Unleashing the Power of JAX-WS RI: Spring, Stateful Web Services, SMTP, and More... :-). At least Kohsuke, and probably also Jitu, will also be present at GlassFish Day - register for free here.