If you want to make this behaviour the default one, you have to configure this in the object mapper that is responsible for serialization/deserialization of objects to json.
In Quarkus, you can use either Jackson or JsonB for object mapping.
For Jackson, you can control the behaviour of field names using PropertyNamingStrategy which you want to set to SNAKE_CASE
. To set this globally, create an ObjectMapperCustomizer
like so:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import io.quarkus.jackson.ObjectMapperCustomizer;
import javax.inject.Singleton;
@Singleton
public class ObjectMapperConfig implements ObjectMapperCustomizer {
@Override
public void customize(ObjectMapper objectMapper) {
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
}
}
You can control many more aspects of serialization e.g. ignore unknown props during deserialization, date formatting, etc.
You need to have a dep to quarkus-resteasy-jackson
:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
If you want to use JsonB (quarkus-resteasy-jsonb
) then you can try it with the following JsonbConfigCustomizer
import io.quarkus.jsonb.JsonbConfigCustomizer;
import javax.inject.Singleton;
import javax.json.bind.JsonbConfig;
import javax.json.bind.config.PropertyNamingStrategy;
@Singleton
public class JsonBCustomizer implements JsonbConfigCustomizer {
public void customize(JsonbConfig config) {
config.withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_UNDERSCORES);
}
}