1

I have a project that has ability of Core Spring and I want to add RestFul Ability, Actually I want to send and Receive JSON data through Spring Web MVC or Whatelse others. Imagine that, I have a Hibernate Entity names is category. I want to send this Entity as Json Data with Spring and I want to send List as Json Data,also .Naturally, I want to take this Json data from someWhere with Spring .

How can I do this Ability with spring ? Are there any tutorials?

Cetin Imre
  • 331
  • 1
  • 8
  • 15

2 Answers2

2

You will have to have jackson in your Classpath for Spring to render the response as json.

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html#view-json-mapping

Spring 3.0 making JSON response using jackson message converter

Community
  • 1
  • 1
  • Again hello guys, I did your suggestion but I have a new problem with Json,When I tyr to send List with ResponseBody Annotation,it download as a file without extension and I am downloading it open it so I can see my data as Json Format, Is this normal to download a file? – Cetin Imre Oct 27 '11 at 08:14
  • @CetinImre if you use Firefox it opens is as a downloadable file however Chromium doesn't. Plugin is here: https://addons.mozilla.org/en-US/firefox/addon/jsonview/ – kamaci Nov 30 '11 at 19:20
1

In addition you also need to make sure that you have the following line in your Spring XML:

<context:annotation-config />

Otherwise jackson will not be enabled.

As the result, all methods which are mapped by @ResponseBody and returns object will be serialized and returned as response using application/json content type.

danny.lesnik
  • 18,479
  • 29
  • 135
  • 200
  • My Json data looks like [{"name":"cat","id":1,"category":null,"categories":null}{"name":"cat","id":1,"category":null,"categories":null},{"name":"cat","id":1,"category":null,"categories":null},{"name":"cat","id":1,"category":null,"categories":null},{"name":"cat","id":1,"category":null,"categories":null}] but ı dont see information beginning of json data like this ‎{"status":"OK","msg":"","count":"37","results": how can I this? – Cetin Imre Oct 27 '11 at 22:46