Integrating JackSon for JSON View with Spring 2.5

2.5k Views Asked by At

We are using Spring 2.5 and spring-json for JSON support. We have the below configuration in views.xml

<bean name="jsonView" class="org.springframework.web.servlet.view.json.JsonView"/>

Now, we have learnt that Spring 3.x uses JackSon API internally for JSON support. My question is how can we override the default implementation of Spring 2.5 to use JackSon - The way Spring 3.x begins.

Note: We don't want to migrate my Spring version, but, want Spring 2.5 to use this JackSon API instead of Spring-Json

1

There are 1 best solutions below

1
On

Is it possible to replace Spring's JSON support without breaking it ?

Unfortunately, Spring's own documentation states that Spring-json is "deeply" a component of the existing Spring 2.5 framework.

See : http://spring-json.sourceforge.net/

That said - removing the dependencies on spring-json, adding your own JSON parser, and rebuilding spring can be done. I assume this will require a lot of work given that spring-json is a major component of the whole Spring MVC suite.

An alternative : Building a Facade

In addition, I don't know of any Java EE specification for Json libraries which implies that there is a good chance that all internal Spring json dependencies are specific to the APIs defined by Spring-json [compare this, for example, with JPA, which is generically defined by Java EE, so that it is easy to replace many a DAO framework].

Generally, you can package any sort of JSon library as a Spring component that will be available in the application context. Now - if you reimplement the necessary interfaces using the facade pattern, using Jackson under the hood, your version of Spring 2.5 should work the same. Alternatively, you could intercept Json related calls of interest using Spring's aspect oriented injection libraries, and reroute them as necessary.

Again, however, these are all advanced tasks - they would be excellent learning projects but I'm not sure that the time investment would really pay off if this is a production application.

http://www.javaworld.com/javaworld/jw-02-2008/jw-02-springcomponents.html