John Cartwright
John Cartwright

Reputation: 599

SpringBoot RestController not recognizing spring.jackson.property-naming-strategy property

I have a SpringBoot (2.5.x) RestController which is returning Lists and would like to force the JSON representation to use specific naming convention for the properties. I've tried the spring.jackson.property-naming-strategy property in application.properties but it seems to have no effect. Also tried custom MappingJackson2HttpMessageConverter, using setPropertyNamingStrategy on the Autowired objectMapper, and using the @JsonNaming annotation in the controller class.

Any ideas on what I'm doing wrong?

Thanks!

--john

Upvotes: 0

Views: 1032

Answers (2)

John Cartwright
John Cartwright

Reputation: 599

This is what I ended up doing:

    import com.fasterxml.jackson.annotation.JsonInclude
    import com.fasterxml.jackson.annotation.JsonInclude.Include
    import com.fasterxml.jackson.databind.PropertyNamingStrategies
    import com.fasterxml.jackson.databind.annotation.JsonNaming
    
    @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
    @JsonInclude(Include.NON_NULL)
    class Facility {
        String facility
        String facilityCode
        Integer sampleCount
    }

Upvotes: 0

暗恋这件小事
暗恋这件小事

Reputation: 1

Put this on the class

@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)

But it is outdated

At the same time it is still available

I don't know why

my spring boot 2.5.4

Upvotes: 0

Related Questions