I have REST API with property in application.properties as below:
spring.jackson.property-naming-strategy: CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
Everything is OK! But when I use RestTemplate to do as below, but I found all key in Snake Case is null (ex. nameEnglish), but regular key name are ok (ex. rank), how can I solve this problem?
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(exclude = {"id"})
@Entity
public class Brand implements Serializable {
    private static final long serialVersionUID = 9165709510160554127L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Version
    private Integer version;
    private String nameChinese;
    private String nameEnglish;
    private String rank;
}
I saved a data as below:
Saved Brand: Brand(id=1, version=1, nameChinese=乐高, nameEnglish=Lego, rank=Top)
But when I try code as below:
Brand brands = restTemplate.getForObject("http://localhost:8080/api/brand/lego", Brand.class);
System.out.println(brands);
The result as below, you will see all Camel Case properties in null, though I set value to them:
Saved Brand: Brand(id=1, version=1, nameChinese=null, nameEnglish=null, rank=Top)
The Json format result form CocoaRestCLient
{
    "id": 1,
    "country_chinese": "芬兰",
    "version": 1,
    "homepage_url": "http://www.lego.com",
    "country_english": "Finland",
    "name_english": "Lego",
    "rank": "Top",
    "name_chinese": "乐高"
}
                I think you have a typo in application.properties. Correct value is either:
spring.jackson.property-naming-strategy=CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
or
spring.jackson.property-naming-strategy=com.fasterxml.jackson.databind.PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy
See Appendix A. Common application properties from Spring Boot Reference Guide:
spring.jackson.property-naming-strategy= # One of the constants on Jackson's PropertyNamingStrategy. Can also be a fully-qualified class name of a PropertyNamingStrategy subclass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With