Results 1 to 5 of 5

Thread: Support for Json (Jackson) Serialization within a service (not web controller)

  1. #1
    Join Date
    Oct 2007
    Posts
    11

    Default Support for Json (Jackson) Serialization within a service (not web controller)

    Hi together,
    as we all know, there is a nice support of Jackson JSON Serialization in Spring Web, which is easy to use within Web Controllers (@ResponseBody etc.). In my situation, I want to reuse the configured Jackson Environment in order to serialize to JSON within my service.

    I do not want to create an ObjectMapper every time, I want to use the Jackson Library. Is there any easy way to reuse the configured ObjectMapper which is automatically used, when using Json in a WebController?

    Cheers
    fr

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,630

    Default

    What is wrong with simply injecting the ObjectMapper? Configure the ObjectMapper and inject it into your service.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2007
    Posts
    11

    Default

    Quote Originally Posted by Marten Deinum View Post
    What is wrong with simply injecting the ObjectMapper? Configure the ObjectMapper and inject it into your service.
    Of course I can register my own ObjectMapper as a bean and then autowire it. I was searching for a way to avoid configuring a second ObjectMapper, as there must be an already configured one, which is used automatically when used in the WebController (with @ResponseBody).

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,630

    Default

    No there isn't... That is constructed internally and not registered as a bean... However the spring components allow for the ObjectMapper to be injected so you could explicitly configure one and inject it into the spring components also.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Oct 2007
    Posts
    11

    Default

    Perfect! Thanks for your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •