Are there any Java client libraries for OpenSocial?

Java developers: how do you like your client libraries for JSON-based web APIs?

  • I'm designing a set of API client libraries for a JSON semi-RESTful web API. I know how such libraries should work in Ruby and Python (where JSON maps directly to built-in language datastructures) but I'm not sure how to approach the problem for Java. Should I be baking class definitions of the web API's core concepts in to the Java library? Doing so means that when new features are added to the web API the Java library will be unable to access them unless it is updated. What are some great examples of Java client libraries for JSON (or XML) APIs?

  • Answer:

    I would take a look at https://github.com/FasterXML/jackson, a fast, fully featured JSON processing library. (Disclaimer, I'm one of the maintainers). It supports both a low-memory, high-performance streaming model, as well as a full datatype binding and marshaling model for ease of use. Of note, both the AWS and Windows Azure REST client libraries for Java make use of Jackson for JSON marshaling. To answer your question about APIs: the common paradigm is to implement API classes that model the JSON requests your service expects, and use Jackson's databinding features to marshal those objects. If you want to support extensibility for the future, your API object can contain an "any getter/any setter" pair, that allows the user to add arbitrary key/value pairs to an API object, giving users the potential for access to future features before the client libraries are updated. This feature is blogged about here: http://www.cowtowncoder.com/blog/archives/2010/09/entry_414.html. I would also look into the Jersey client: https://jersey.java.net/documentation/latest/user-guide.html#client-jdk, a JAX-RS 2.0 client library which provides a convenient abstraction to access web resources in both synchronous and asynchronous modes, and easily inter-operates with Jackson for automatic datatype marshalling.

Christopher Currie at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.