|
Very interesting. I did the exact same thing recently as part of a prototype. I hope to get something like this in Spring 2.1 along with a JsonServiceExporter. Rob Rob, json-lib transforms beans, maps, collections and arrays to JSON format, but the current development snapshot can transform JSON to DynaBeans, collections, arrays and beans (althought the primitive array conversion still needs some work). Andres json-lib implementation of a ServiceExporter with dojo support I was exactly on that track when I wrote the inappropriately named SmdServiceExporter. var testClass = new dojo.rpc.JsonService("/dojo_test_server/remoting/TestService"); This is enough to call a method on a server side bean and pass the result to the mapContentCallBack function.
I think that we have three different issues mixed, let me explain, In renderMergedOutputModel, you have to actually set the contentType of the response, like response.setContentType(this.getContentType()); I would like to propose some changes to JsonView: 1. Change the default content type to "application/json" (see RFC 4627). Updated code to maven2, json-lib-1.0b2, ezmorph-1.0, jstester-1.3. Wow, that was quick update ! Some notes on JsonView v2: 1. Please add an overloaded version of the createJSON method that has request and response parameters (e.g. for access to session data). Update with latest suggestions from M.H. Avegaart I've noticed the use of an old version of the json-lib (the stable version at the time of writing is 2.1). Watch at the attached file JsonView.java. View updated to support json-lib 2.1 I suggest adding an extra method between renderMergedOutputModel and createJSON that allowes for overriding when JSON output is written directly to the response (e.g. when using net.sf.json.util.JSONBuilder). Change: protected void writeJSON(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { I decided to release JsonView as an extension of Json-lib. If anyone is interested the package is available at M.H. Avegaart: I included your latest suggestion too. How does one use this? Is there documentation anywhere? Please checkout the features in http://spring-json.sourceforge.net/ Speaking for the JsonView code attached to this issue (latest version [1.0.1] available at http://sourceforge.net/projects/json-lib I see there is also a project that seems to solve this called spring-json http://spring-json.sourceforge.net/ Which implementation, or yet a third solution will be included in Spring 3? Rogier, what is the status for SmdServiceExporter? I'm searching scalable, supportable solution for my projects to build a bridge between Browser and Spring's Services - I just want to be able to call remote method using Javacript and searching for an appropriate ServiceExporter. In this issue we can see two solutions: 1) SmdServiceExporter 2) JSONRPCServiceExporter. Advantages of SmdServiceExporter:
Disadvantages of SmdServiceExporter:
Advantages of JSONRPCServiceExporter:
Disadvantages of JSONRPCServiceExporter:
Conclusion: I think SmdServiceExporter is better than JSONRPCServiceExporter for a long perspective because:
But I found some difficulties compiling SmdServiceExporter with latest versions of dojo and json-lib and I think that it doesn't support complex types. So if Rogier would share us updated version it would be appreciated. BR I've created a project for a springframework JSON-RPC based RemoteExporter at the following URL: http://code.google.com/p/spring-jsonrpc/ It's based on the specification being written at: http://groups.google.com/group/json-rpc note: The code for this project is not the same code attached to this issue - it's completely different. I just figured I'd let everyone know that it exists |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Maven project with JsonView + tests. Includes the following dependencies:

json-lib – transforms model to JSON – http://json-lib.sourceforge.net
jstester – tests javaScript code inside java – http://jstester.sourceforge.net