Announcement Announcement Module
Collapse
No announcement yet.
Support for Json (Jackson) Serialization within a service (not web controller) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    What is wrong with simply injecting the ObjectMapper? Configure the ObjectMapper and inject it into your service.

    Comment


    • #3
      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).

      Comment


      • #4
        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.

        Comment


        • #5
          Perfect! Thanks for your help!

          Comment

          Working...
          X