3

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

hop
  • 2,518
  • 11
  • 40
  • 56
  • If JsonView works, why do you care if Jackson is used or not? – skaffman Dec 08 '11 at 09:44
  • I understand that Spring has moved to JackSon in 3.x maily because its faster and better. We have serious speed issues and desprate to make the app fast ! – hop Dec 08 '11 at 11:02
  • Do you have evidence that `JsonView` is the cause of your performance problem? – skaffman Dec 08 '11 at 12:20
  • No. I need to measure the performance of JsonView against JsonView with JackSon and then benchmark it. But, I am struck in the middle! – hop Dec 08 '11 at 12:47
  • 3
    If `JsonView` isn't your bottleneck, then using Jackson will not help your application performance. You need to establish what is slow, before you try and make it faster. – skaffman Dec 08 '11 at 13:39
  • 1
    Ha ! Its not a question of JsonView being bottleneck. Its just how faster Spring with JackSon view is compared to previous versions – hop Dec 09 '11 at 03:05

1 Answers1

0

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

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
jayunit100
  • 17,388
  • 22
  • 92
  • 167
  • >`I don't know of any Java EE specification for Json libraries` - For future reference, since this month there is: http://infoq.com/news/2013/04/standard-java-api-for-json – Arjan Tijms May 04 '13 at 21:30