How to configure Jackson mapper












0















How can I globally configure json serializer for http4k? For example, snake case field names or formatting DateTime as ISO8601.










share|improve this question























  • The solution is likely similar to the answer on this issue reported to http4k: github.com/http4k/http4k/issues/183 where you have to create your own subtype of ConfigurableJackson ... not the easiest way to have extensibility, but appears to be the option.

    – Jayson Minard
    Nov 18 '18 at 16:01











  • Yeah, I did the same. Creating another object subclassing from ConfigurableJackson. Would you mind creating an answer to my question?

    – alisabzevari
    Nov 18 '18 at 18:33
















0















How can I globally configure json serializer for http4k? For example, snake case field names or formatting DateTime as ISO8601.










share|improve this question























  • The solution is likely similar to the answer on this issue reported to http4k: github.com/http4k/http4k/issues/183 where you have to create your own subtype of ConfigurableJackson ... not the easiest way to have extensibility, but appears to be the option.

    – Jayson Minard
    Nov 18 '18 at 16:01











  • Yeah, I did the same. Creating another object subclassing from ConfigurableJackson. Would you mind creating an answer to my question?

    – alisabzevari
    Nov 18 '18 at 18:33














0












0








0








How can I globally configure json serializer for http4k? For example, snake case field names or formatting DateTime as ISO8601.










share|improve this question














How can I globally configure json serializer for http4k? For example, snake case field names or formatting DateTime as ISO8601.







kotlin http4k






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 13:54









alisabzevarialisabzevari

3,78212751




3,78212751













  • The solution is likely similar to the answer on this issue reported to http4k: github.com/http4k/http4k/issues/183 where you have to create your own subtype of ConfigurableJackson ... not the easiest way to have extensibility, but appears to be the option.

    – Jayson Minard
    Nov 18 '18 at 16:01











  • Yeah, I did the same. Creating another object subclassing from ConfigurableJackson. Would you mind creating an answer to my question?

    – alisabzevari
    Nov 18 '18 at 18:33



















  • The solution is likely similar to the answer on this issue reported to http4k: github.com/http4k/http4k/issues/183 where you have to create your own subtype of ConfigurableJackson ... not the easiest way to have extensibility, but appears to be the option.

    – Jayson Minard
    Nov 18 '18 at 16:01











  • Yeah, I did the same. Creating another object subclassing from ConfigurableJackson. Would you mind creating an answer to my question?

    – alisabzevari
    Nov 18 '18 at 18:33

















The solution is likely similar to the answer on this issue reported to http4k: github.com/http4k/http4k/issues/183 where you have to create your own subtype of ConfigurableJackson ... not the easiest way to have extensibility, but appears to be the option.

– Jayson Minard
Nov 18 '18 at 16:01





The solution is likely similar to the answer on this issue reported to http4k: github.com/http4k/http4k/issues/183 where you have to create your own subtype of ConfigurableJackson ... not the easiest way to have extensibility, but appears to be the option.

– Jayson Minard
Nov 18 '18 at 16:01













Yeah, I did the same. Creating another object subclassing from ConfigurableJackson. Would you mind creating an answer to my question?

– alisabzevari
Nov 18 '18 at 18:33





Yeah, I did the same. Creating another object subclassing from ConfigurableJackson. Would you mind creating an answer to my question?

– alisabzevari
Nov 18 '18 at 18:33












2 Answers
2






active

oldest

votes


















0














Since the ObjectMapper instance is private within ConfigurableJackson you cannot get at it after construction to do any configuration.



So you either need to construct your own direct instance of ConfigurableJackson and pass in a customized ObjectMapper or you need to subclass ConfigurableJackson with your own class. And then during the constructor, create an ObjectMapper (see example below) or intercept one being passed into your constructor and change its settings.



Whatever you do, be sure you do not break the http4k framework or anything else that might be using the same instance. You can see the defaults used by http4k declared in their source code:





object Jackson : ConfigurableJackson(ObjectMapper()
.registerModule(defaultKotlinModuleWithHttp4kSerialisers)
.disableDefaultTyping()
.configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(FAIL_ON_IGNORED_PROPERTIES, false)
.configure(USE_BIG_DECIMAL_FOR_FLOATS, true)
.configure(USE_BIG_INTEGER_FOR_INTS, true)
)


You can use code similar to above to create your own instance.



See this thread for some conversation about this topic: https://github.com/http4k/http4k/issues/183






share|improve this answer

































    -1














    You don't necessarily need to extend ConfigurableJackson - it's just that extending it is the most convenient way to do this (in our experience).



    All configuration is done by tweaking the ObjectMapper instance which is injected into the ConfigurableJackson constructor - the ConfigurableJackson itself just provides the wrapper API around that mapper. The question is to do with standard configuration of Jackson, so you should seek answers to your specific questions (snake case etc) from the Jackson docs directly as http4k doesn't own that API.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361644%2fhow-to-configure-jackson-mapper%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Since the ObjectMapper instance is private within ConfigurableJackson you cannot get at it after construction to do any configuration.



      So you either need to construct your own direct instance of ConfigurableJackson and pass in a customized ObjectMapper or you need to subclass ConfigurableJackson with your own class. And then during the constructor, create an ObjectMapper (see example below) or intercept one being passed into your constructor and change its settings.



      Whatever you do, be sure you do not break the http4k framework or anything else that might be using the same instance. You can see the defaults used by http4k declared in their source code:





      object Jackson : ConfigurableJackson(ObjectMapper()
      .registerModule(defaultKotlinModuleWithHttp4kSerialisers)
      .disableDefaultTyping()
      .configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
      .configure(FAIL_ON_IGNORED_PROPERTIES, false)
      .configure(USE_BIG_DECIMAL_FOR_FLOATS, true)
      .configure(USE_BIG_INTEGER_FOR_INTS, true)
      )


      You can use code similar to above to create your own instance.



      See this thread for some conversation about this topic: https://github.com/http4k/http4k/issues/183






      share|improve this answer






























        0














        Since the ObjectMapper instance is private within ConfigurableJackson you cannot get at it after construction to do any configuration.



        So you either need to construct your own direct instance of ConfigurableJackson and pass in a customized ObjectMapper or you need to subclass ConfigurableJackson with your own class. And then during the constructor, create an ObjectMapper (see example below) or intercept one being passed into your constructor and change its settings.



        Whatever you do, be sure you do not break the http4k framework or anything else that might be using the same instance. You can see the defaults used by http4k declared in their source code:





        object Jackson : ConfigurableJackson(ObjectMapper()
        .registerModule(defaultKotlinModuleWithHttp4kSerialisers)
        .disableDefaultTyping()
        .configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
        .configure(FAIL_ON_IGNORED_PROPERTIES, false)
        .configure(USE_BIG_DECIMAL_FOR_FLOATS, true)
        .configure(USE_BIG_INTEGER_FOR_INTS, true)
        )


        You can use code similar to above to create your own instance.



        See this thread for some conversation about this topic: https://github.com/http4k/http4k/issues/183






        share|improve this answer




























          0












          0








          0







          Since the ObjectMapper instance is private within ConfigurableJackson you cannot get at it after construction to do any configuration.



          So you either need to construct your own direct instance of ConfigurableJackson and pass in a customized ObjectMapper or you need to subclass ConfigurableJackson with your own class. And then during the constructor, create an ObjectMapper (see example below) or intercept one being passed into your constructor and change its settings.



          Whatever you do, be sure you do not break the http4k framework or anything else that might be using the same instance. You can see the defaults used by http4k declared in their source code:





          object Jackson : ConfigurableJackson(ObjectMapper()
          .registerModule(defaultKotlinModuleWithHttp4kSerialisers)
          .disableDefaultTyping()
          .configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
          .configure(FAIL_ON_IGNORED_PROPERTIES, false)
          .configure(USE_BIG_DECIMAL_FOR_FLOATS, true)
          .configure(USE_BIG_INTEGER_FOR_INTS, true)
          )


          You can use code similar to above to create your own instance.



          See this thread for some conversation about this topic: https://github.com/http4k/http4k/issues/183






          share|improve this answer















          Since the ObjectMapper instance is private within ConfigurableJackson you cannot get at it after construction to do any configuration.



          So you either need to construct your own direct instance of ConfigurableJackson and pass in a customized ObjectMapper or you need to subclass ConfigurableJackson with your own class. And then during the constructor, create an ObjectMapper (see example below) or intercept one being passed into your constructor and change its settings.



          Whatever you do, be sure you do not break the http4k framework or anything else that might be using the same instance. You can see the defaults used by http4k declared in their source code:





          object Jackson : ConfigurableJackson(ObjectMapper()
          .registerModule(defaultKotlinModuleWithHttp4kSerialisers)
          .disableDefaultTyping()
          .configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
          .configure(FAIL_ON_IGNORED_PROPERTIES, false)
          .configure(USE_BIG_DECIMAL_FOR_FLOATS, true)
          .configure(USE_BIG_INTEGER_FOR_INTS, true)
          )


          You can use code similar to above to create your own instance.



          See this thread for some conversation about this topic: https://github.com/http4k/http4k/issues/183







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '18 at 5:34

























          answered Nov 19 '18 at 4:37









          Jayson MinardJayson Minard

          39.5k17109173




          39.5k17109173

























              -1














              You don't necessarily need to extend ConfigurableJackson - it's just that extending it is the most convenient way to do this (in our experience).



              All configuration is done by tweaking the ObjectMapper instance which is injected into the ConfigurableJackson constructor - the ConfigurableJackson itself just provides the wrapper API around that mapper. The question is to do with standard configuration of Jackson, so you should seek answers to your specific questions (snake case etc) from the Jackson docs directly as http4k doesn't own that API.






              share|improve this answer




























                -1














                You don't necessarily need to extend ConfigurableJackson - it's just that extending it is the most convenient way to do this (in our experience).



                All configuration is done by tweaking the ObjectMapper instance which is injected into the ConfigurableJackson constructor - the ConfigurableJackson itself just provides the wrapper API around that mapper. The question is to do with standard configuration of Jackson, so you should seek answers to your specific questions (snake case etc) from the Jackson docs directly as http4k doesn't own that API.






                share|improve this answer


























                  -1












                  -1








                  -1







                  You don't necessarily need to extend ConfigurableJackson - it's just that extending it is the most convenient way to do this (in our experience).



                  All configuration is done by tweaking the ObjectMapper instance which is injected into the ConfigurableJackson constructor - the ConfigurableJackson itself just provides the wrapper API around that mapper. The question is to do with standard configuration of Jackson, so you should seek answers to your specific questions (snake case etc) from the Jackson docs directly as http4k doesn't own that API.






                  share|improve this answer













                  You don't necessarily need to extend ConfigurableJackson - it's just that extending it is the most convenient way to do this (in our experience).



                  All configuration is done by tweaking the ObjectMapper instance which is injected into the ConfigurableJackson constructor - the ConfigurableJackson itself just provides the wrapper API around that mapper. The question is to do with standard configuration of Jackson, so you should seek answers to your specific questions (snake case etc) from the Jackson docs directly as http4k doesn't own that API.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 18 '18 at 18:47









                  David DDavid D

                  543




                  543






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361644%2fhow-to-configure-jackson-mapper%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Xamarin.form Move up view when keyboard appear

                      Post-Redirect-Get with Spring WebFlux and Thymeleaf

                      Anylogic : not able to use stopDelay()