3

I use spring mvc 4.0.2. I defined a class with several boolean properties, such as isSoldout, autoMergeWhileChoose . The simplified code as

public class Dish implements Serializable{
    private boolean autoMergeWhileChoose = true;
    private boolean isNew = false;
    private boolean isSpecial = false;
    private boolean isSoldOut = false;
    ......
}

I get the json from client side. I found the properties with is- prefix have been removed the is-. For example, isSoldOut changes to soldOut. But the other boolean properties without prefix is- don't change. I show a part of the json here

{
    ...
    "autoMergeWhileChoose" : true,
    "new" : false,
    "soldOut" : false,
    "special" : false
    ...
}

You can find the first autoMergeWhileChoose does not change, but the following three are changed without the prefix is-.

The convertor is MappingJackson2HttpMessageConverter, and the config file is

  <beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <beans:property name="messageConverters">
      <beans:list>
        <beans:bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
          <beans:property name="prettyPrint" value="true"/>
        </beans:bean>
      </beans:list>
    </beans:property>
  </beans:bean>

Are there some settings to deal with it?

Songtao Lou
  • 41
  • 11
  • Please post the object where you define the properties – Jens Oct 30 '17 at 07:12
  • 3
    @SongtaoLou I think you can use `@JsonProperty("isSoldout")` above field/getter in your class. Other option is to change getter name to something like `isIsSoldout` but it will look ugly. – varren Oct 30 '17 at 07:27
  • Workaround please check this link https://stackoverflow.com/questions/32270422/jackson-renames-primitive-boolean-field-by-removing-is – blitzen12 Oct 30 '17 at 08:15
  • @varren thank you , I feel you idea would be worked. I will try it now. – Songtao Lou Oct 30 '17 at 10:05
  • @varren The result changed to `isSoldout` now, but `soldout` is still existing. now both of them have same value. but it is not serious. Thank you – Songtao Lou Oct 30 '17 at 10:23

0 Answers0