|
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).
So if the intent of JsonServiceExporter is to mirror the other service exporters (client-server with two-way encoding/decoding) I think json-lib can help you accomplish that goal. Andres json-lib implementation of a ServiceExporter with dojo support
I was exactly on that track when I wrote the inappropriately named SmdServiceExporter.
This also exposes the service description in SMD format so that it can be accessed from a dojo client with only a few keystrokes: 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,
1. allow for a Spring MVC view to export/render its model as JSON (this is solved by the JSONView) 2. a Spring Remoting solution that uses json-rpc as its communication protocol (think HessianProxyFactoryBean -> JsonRPCProxyFactoryBean), this is solved by the Spring JSONExporter 3. integration of an AJAX toolkit and Spring beans, the beans will respond to calls made by the XHR. There is already an ongoing effor in Spring Modules's XT framework on this, but it is not based in the DOJO toolkit (as version 0.6). 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.
Added changes proposed by Julian Dreißig and M.H. Avegaart 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
Added javadocs too I've noticed the use of an old version of the json-lib (the stable version at the time of writing is 2.1).
I wrote an updated version of the view, using the new 2.x syntax for the configuration (exported as a bean property). 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
http://sourceforge.net/project/showfiles.php?group_id=171425 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
JsonView is responsible for exporting data as JSON only (it is a view after all), any AJAX integration must be handled by your own components, thus giving full freedom to choose what makes more sense for your app. 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 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
json-lib – transforms model to JSON – http://json-lib.sourceforge.net
jstester – tests javaScript code inside java – http://jstester.sourceforge.net