Set DEFAULT_VIEW_INCLUSION in YAML file












0















How I can set properties to DEFAULT_VIEW_INCLUSION in yml file in Spring?



Now, I have this



spring:
jackson:
mapper:
DEFAULT_VIEW_INCLUSION: true



But doesn't work.










share|improve this question





























    0















    How I can set properties to DEFAULT_VIEW_INCLUSION in yml file in Spring?



    Now, I have this



    spring:
    jackson:
    mapper:
    DEFAULT_VIEW_INCLUSION: true



    But doesn't work.










    share|improve this question



























      0












      0








      0








      How I can set properties to DEFAULT_VIEW_INCLUSION in yml file in Spring?



      Now, I have this



      spring:
      jackson:
      mapper:
      DEFAULT_VIEW_INCLUSION: true



      But doesn't work.










      share|improve this question
















      How I can set properties to DEFAULT_VIEW_INCLUSION in yml file in Spring?



      Now, I have this



      spring:
      jackson:
      mapper:
      DEFAULT_VIEW_INCLUSION: true



      But doesn't work.







      json spring jackson






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 17 '17 at 9:18









      Anthon

      30.1k1793147




      30.1k1793147










      asked Jul 17 '17 at 7:06







      user6216601































          3 Answers
          3






          active

          oldest

          votes


















          0














          Try with Java Config:



          @Configuration
          public class JacksonMapperConfig {

          @Bean
          public ObjectMapper objectMapper() {
          ObjectMapper mapper = new ObjectMapper();
          mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
          return mapper;
          }
          }





          share|improve this answer
























          • Thanks, man! :)

            – user6216601
            Jul 17 '17 at 12:05



















          1














          If you're using Spring Boot, you can autowire the ObjectMapper:



          @Configuration
          public class JacksonConfig {

          @Autowired
          private ObjectMapper objectMapper;

          @PostConstruct
          public void configureObjectMapper() {
          objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
          }

          }





          share|improve this answer































            0














            This is a somewhat older question, but the questioner asked about how to do it in YAML in Spring Boot (using the "application.yml" file), not how to override the Mapper. Since overriding the Mapper causes you to lose all the other auto-configure benefits, let's assume the mode of overriding was important to the questioner. So, I'll answer the YAML question.



            The questioner's problem is the syntax. This is how the Spring Boot documentation says you set it in YAML:



            spring:
            jackson:
            default-property-inclusion: non_null


            Note the indentation, it's important. "spring" is up against the left margin, "Jackson" is one tab-stop indented, and then the property is another tab-stop indented. There must be a space between the ":" and the "non_null" property value or the parser doesn't see the property name correctly.



            If you have other Spring properties to set, this section of your "application.yml" YAML file might look something like this:



            spring:
            cloud:
            config:
            enabled: false
            jackson:
            default-property-inclusion: non_null


            Cautionary Note

            That said, I tried to use this setting in a project with Spring Boot Starter v2.0.3 as its Parent, to suppress Nulls from Spring HATEOAS' ResourceSupport class. It didn't suppress any nulls in the Response objects.



            This is where the overriding suggestion can offer a clue as to why the setting isn't 'working'. In my case, because the project used Jersey with Spring Boot instead of Spring MVC, I discovered that, for some reason, the JerseyConfiguration was overriding Boot's auto-configured mapper, and it explicitly set the JsonInclude to ALWAYS - so no Spring Boot setting was going to solve it:



            public class JerseyConfiguration extends ResourceConfig {

            @Autowired
            public JerseyConfiguration(ObjectMapper objectMapper) {
            objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);

            packages("<removed actual class packages>");
            register(ResponseFilter.class);
            register(new ObjectMapperContextResolver(objectMapper));
            configureSwagger();
            }


            So, one answer said to override the Mapper to 'solve' the problem. But you might find that your problem is occurring because someone already overrode the Spring Boot Mapper and has set an explicit include policy already. That was the issue on my project and changing the policy in the Jersey Config fixed my issue.






            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%2f45137920%2fset-default-view-inclusion-in-yaml-file%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown
























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Try with Java Config:



              @Configuration
              public class JacksonMapperConfig {

              @Bean
              public ObjectMapper objectMapper() {
              ObjectMapper mapper = new ObjectMapper();
              mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
              return mapper;
              }
              }





              share|improve this answer
























              • Thanks, man! :)

                – user6216601
                Jul 17 '17 at 12:05
















              0














              Try with Java Config:



              @Configuration
              public class JacksonMapperConfig {

              @Bean
              public ObjectMapper objectMapper() {
              ObjectMapper mapper = new ObjectMapper();
              mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
              return mapper;
              }
              }





              share|improve this answer
























              • Thanks, man! :)

                – user6216601
                Jul 17 '17 at 12:05














              0












              0








              0







              Try with Java Config:



              @Configuration
              public class JacksonMapperConfig {

              @Bean
              public ObjectMapper objectMapper() {
              ObjectMapper mapper = new ObjectMapper();
              mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
              return mapper;
              }
              }





              share|improve this answer













              Try with Java Config:



              @Configuration
              public class JacksonMapperConfig {

              @Bean
              public ObjectMapper objectMapper() {
              ObjectMapper mapper = new ObjectMapper();
              mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
              return mapper;
              }
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jul 17 '17 at 7:15









              codependentcodependent

              7,2701060128




              7,2701060128













              • Thanks, man! :)

                – user6216601
                Jul 17 '17 at 12:05



















              • Thanks, man! :)

                – user6216601
                Jul 17 '17 at 12:05

















              Thanks, man! :)

              – user6216601
              Jul 17 '17 at 12:05





              Thanks, man! :)

              – user6216601
              Jul 17 '17 at 12:05













              1














              If you're using Spring Boot, you can autowire the ObjectMapper:



              @Configuration
              public class JacksonConfig {

              @Autowired
              private ObjectMapper objectMapper;

              @PostConstruct
              public void configureObjectMapper() {
              objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
              }

              }





              share|improve this answer




























                1














                If you're using Spring Boot, you can autowire the ObjectMapper:



                @Configuration
                public class JacksonConfig {

                @Autowired
                private ObjectMapper objectMapper;

                @PostConstruct
                public void configureObjectMapper() {
                objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
                }

                }





                share|improve this answer


























                  1












                  1








                  1







                  If you're using Spring Boot, you can autowire the ObjectMapper:



                  @Configuration
                  public class JacksonConfig {

                  @Autowired
                  private ObjectMapper objectMapper;

                  @PostConstruct
                  public void configureObjectMapper() {
                  objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
                  }

                  }





                  share|improve this answer













                  If you're using Spring Boot, you can autowire the ObjectMapper:



                  @Configuration
                  public class JacksonConfig {

                  @Autowired
                  private ObjectMapper objectMapper;

                  @PostConstruct
                  public void configureObjectMapper() {
                  objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
                  }

                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 17 '17 at 9:01









                  René WinklerRené Winkler

                  2,89421746




                  2,89421746























                      0














                      This is a somewhat older question, but the questioner asked about how to do it in YAML in Spring Boot (using the "application.yml" file), not how to override the Mapper. Since overriding the Mapper causes you to lose all the other auto-configure benefits, let's assume the mode of overriding was important to the questioner. So, I'll answer the YAML question.



                      The questioner's problem is the syntax. This is how the Spring Boot documentation says you set it in YAML:



                      spring:
                      jackson:
                      default-property-inclusion: non_null


                      Note the indentation, it's important. "spring" is up against the left margin, "Jackson" is one tab-stop indented, and then the property is another tab-stop indented. There must be a space between the ":" and the "non_null" property value or the parser doesn't see the property name correctly.



                      If you have other Spring properties to set, this section of your "application.yml" YAML file might look something like this:



                      spring:
                      cloud:
                      config:
                      enabled: false
                      jackson:
                      default-property-inclusion: non_null


                      Cautionary Note

                      That said, I tried to use this setting in a project with Spring Boot Starter v2.0.3 as its Parent, to suppress Nulls from Spring HATEOAS' ResourceSupport class. It didn't suppress any nulls in the Response objects.



                      This is where the overriding suggestion can offer a clue as to why the setting isn't 'working'. In my case, because the project used Jersey with Spring Boot instead of Spring MVC, I discovered that, for some reason, the JerseyConfiguration was overriding Boot's auto-configured mapper, and it explicitly set the JsonInclude to ALWAYS - so no Spring Boot setting was going to solve it:



                      public class JerseyConfiguration extends ResourceConfig {

                      @Autowired
                      public JerseyConfiguration(ObjectMapper objectMapper) {
                      objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);

                      packages("<removed actual class packages>");
                      register(ResponseFilter.class);
                      register(new ObjectMapperContextResolver(objectMapper));
                      configureSwagger();
                      }


                      So, one answer said to override the Mapper to 'solve' the problem. But you might find that your problem is occurring because someone already overrode the Spring Boot Mapper and has set an explicit include policy already. That was the issue on my project and changing the policy in the Jersey Config fixed my issue.






                      share|improve this answer






























                        0














                        This is a somewhat older question, but the questioner asked about how to do it in YAML in Spring Boot (using the "application.yml" file), not how to override the Mapper. Since overriding the Mapper causes you to lose all the other auto-configure benefits, let's assume the mode of overriding was important to the questioner. So, I'll answer the YAML question.



                        The questioner's problem is the syntax. This is how the Spring Boot documentation says you set it in YAML:



                        spring:
                        jackson:
                        default-property-inclusion: non_null


                        Note the indentation, it's important. "spring" is up against the left margin, "Jackson" is one tab-stop indented, and then the property is another tab-stop indented. There must be a space between the ":" and the "non_null" property value or the parser doesn't see the property name correctly.



                        If you have other Spring properties to set, this section of your "application.yml" YAML file might look something like this:



                        spring:
                        cloud:
                        config:
                        enabled: false
                        jackson:
                        default-property-inclusion: non_null


                        Cautionary Note

                        That said, I tried to use this setting in a project with Spring Boot Starter v2.0.3 as its Parent, to suppress Nulls from Spring HATEOAS' ResourceSupport class. It didn't suppress any nulls in the Response objects.



                        This is where the overriding suggestion can offer a clue as to why the setting isn't 'working'. In my case, because the project used Jersey with Spring Boot instead of Spring MVC, I discovered that, for some reason, the JerseyConfiguration was overriding Boot's auto-configured mapper, and it explicitly set the JsonInclude to ALWAYS - so no Spring Boot setting was going to solve it:



                        public class JerseyConfiguration extends ResourceConfig {

                        @Autowired
                        public JerseyConfiguration(ObjectMapper objectMapper) {
                        objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);

                        packages("<removed actual class packages>");
                        register(ResponseFilter.class);
                        register(new ObjectMapperContextResolver(objectMapper));
                        configureSwagger();
                        }


                        So, one answer said to override the Mapper to 'solve' the problem. But you might find that your problem is occurring because someone already overrode the Spring Boot Mapper and has set an explicit include policy already. That was the issue on my project and changing the policy in the Jersey Config fixed my issue.






                        share|improve this answer




























                          0












                          0








                          0







                          This is a somewhat older question, but the questioner asked about how to do it in YAML in Spring Boot (using the "application.yml" file), not how to override the Mapper. Since overriding the Mapper causes you to lose all the other auto-configure benefits, let's assume the mode of overriding was important to the questioner. So, I'll answer the YAML question.



                          The questioner's problem is the syntax. This is how the Spring Boot documentation says you set it in YAML:



                          spring:
                          jackson:
                          default-property-inclusion: non_null


                          Note the indentation, it's important. "spring" is up against the left margin, "Jackson" is one tab-stop indented, and then the property is another tab-stop indented. There must be a space between the ":" and the "non_null" property value or the parser doesn't see the property name correctly.



                          If you have other Spring properties to set, this section of your "application.yml" YAML file might look something like this:



                          spring:
                          cloud:
                          config:
                          enabled: false
                          jackson:
                          default-property-inclusion: non_null


                          Cautionary Note

                          That said, I tried to use this setting in a project with Spring Boot Starter v2.0.3 as its Parent, to suppress Nulls from Spring HATEOAS' ResourceSupport class. It didn't suppress any nulls in the Response objects.



                          This is where the overriding suggestion can offer a clue as to why the setting isn't 'working'. In my case, because the project used Jersey with Spring Boot instead of Spring MVC, I discovered that, for some reason, the JerseyConfiguration was overriding Boot's auto-configured mapper, and it explicitly set the JsonInclude to ALWAYS - so no Spring Boot setting was going to solve it:



                          public class JerseyConfiguration extends ResourceConfig {

                          @Autowired
                          public JerseyConfiguration(ObjectMapper objectMapper) {
                          objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);

                          packages("<removed actual class packages>");
                          register(ResponseFilter.class);
                          register(new ObjectMapperContextResolver(objectMapper));
                          configureSwagger();
                          }


                          So, one answer said to override the Mapper to 'solve' the problem. But you might find that your problem is occurring because someone already overrode the Spring Boot Mapper and has set an explicit include policy already. That was the issue on my project and changing the policy in the Jersey Config fixed my issue.






                          share|improve this answer















                          This is a somewhat older question, but the questioner asked about how to do it in YAML in Spring Boot (using the "application.yml" file), not how to override the Mapper. Since overriding the Mapper causes you to lose all the other auto-configure benefits, let's assume the mode of overriding was important to the questioner. So, I'll answer the YAML question.



                          The questioner's problem is the syntax. This is how the Spring Boot documentation says you set it in YAML:



                          spring:
                          jackson:
                          default-property-inclusion: non_null


                          Note the indentation, it's important. "spring" is up against the left margin, "Jackson" is one tab-stop indented, and then the property is another tab-stop indented. There must be a space between the ":" and the "non_null" property value or the parser doesn't see the property name correctly.



                          If you have other Spring properties to set, this section of your "application.yml" YAML file might look something like this:



                          spring:
                          cloud:
                          config:
                          enabled: false
                          jackson:
                          default-property-inclusion: non_null


                          Cautionary Note

                          That said, I tried to use this setting in a project with Spring Boot Starter v2.0.3 as its Parent, to suppress Nulls from Spring HATEOAS' ResourceSupport class. It didn't suppress any nulls in the Response objects.



                          This is where the overriding suggestion can offer a clue as to why the setting isn't 'working'. In my case, because the project used Jersey with Spring Boot instead of Spring MVC, I discovered that, for some reason, the JerseyConfiguration was overriding Boot's auto-configured mapper, and it explicitly set the JsonInclude to ALWAYS - so no Spring Boot setting was going to solve it:



                          public class JerseyConfiguration extends ResourceConfig {

                          @Autowired
                          public JerseyConfiguration(ObjectMapper objectMapper) {
                          objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);

                          packages("<removed actual class packages>");
                          register(ResponseFilter.class);
                          register(new ObjectMapperContextResolver(objectMapper));
                          configureSwagger();
                          }


                          So, one answer said to override the Mapper to 'solve' the problem. But you might find that your problem is occurring because someone already overrode the Spring Boot Mapper and has set an explicit include policy already. That was the issue on my project and changing the policy in the Jersey Config fixed my issue.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 14 '18 at 16:04

























                          answered Nov 14 '18 at 15:11









                          CelticPoetCelticPoet

                          19529




                          19529






























                              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%2f45137920%2fset-default-view-inclusion-in-yaml-file%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







                              Popular posts from this blog

                              List item for chat from Array inside array React Native

                              Thiostrepton

                              Caerphilly