Reputation: 107
i have upgraded jakson api on spring boot 1.5.8 from jakson 2.8.0 to 2.10.0, since then mapping of object is behaving different.
when i am passing request body on springboot controller having propertyname cityCode sample json
{
cityCode:DEL
}
when adding jsonproperty mapping works fine
@JsonProperty("cityCode")
private String cityCode;
but when i don't add @JsonProperty annotation it looks for CityCode instead. since json passed on request is
{
cityCode:DEL
}
it assing
object{cityCode=null}
please let me know if there is any property which i need to add on spring boot
because in most of my scenario i don't want to add @JsonProperty annotation to class fields
EDIT:
I enable log.level to trace i saw some message related to jackson
POJOPropertyBuilder - Unable to instantiate jackson 2.6 object. Using higher version of jackson.
EDIT2:
Adding Sample Model Class
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
@ApiModel(value = "CityRequest")
public class CityRequest implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty
private String cityCode;
@ApiModelProperty
private String cityName;
@ApiModelProperty
private String area;
@ApiModelProperty
private List<String> areas;
public String getCityCode() {
return cityCode;
}
public void setCityCode(String cityCode) {
this.cityCode = cityCode;
}
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public List<String> getAreas() {
return areas;
}
public void setAreas(List<String> areas) {
this.areas = areas;
}
@Override
public String toString() {
return "CityRequest{" +
"cityCode='" + cityCode + '\'' +
", cityName='" + cityName + '\'' +
", area='" + area + '\'' +
", areas=" + areas +
'}';
}
}
on the controller method is being passed as
@ApiParam(value = "This field specifies the list of requests", required = true)
@Valid @RequestBody(required = true) CityRequest cityRequest
Upvotes: 0
Views: 255
Reputation: 107
I have used one java api on spring-boot application where object mapper naming strategy is being set to upper_camel_case.
since that class imported on App.java(@SpringBootApplication) upper_camel_case strategy being applied globally.
to fix this globally imposed upper_camel_case strategy i have override the object mapper configuration on App.java and removed
objectMapper.setPropertyNamingStrategy(new UpperCamelCaseStrategy());
now i am able to use default naming strategy on application.
Upvotes: 0
Reputation: 1200
You might want to give this a try as an app property to configure Jackson globally.
spring.jackson.property-naming-strategy=LOWER_CAMEL_CASE
Upvotes: 0
Reputation: 21
I haven't tried but maybe you can try changing the naming strategy to lowerCamelCase:
@JsonNaming(PropertyNamingStrategy.lowerCamelCase.class)
public class City {
private String cityCode;
}
Upvotes: 1