Currently I am moving from spring mvc + tomcat to finatra. I had a weird problem with my api. My api post request expects contextOfText: String
, but when I make request , it returns error and expects context_of_text
. I have never such problem before. Couldn’t know how to search for this problem.. Anyway my work mate told that might be serializer problem. After some research I found some custom jackson module for finatra. Tried to see if it has any effects and fixed with first try. It seems default FinatraJacksonModule is using SNAKE_CASE
, therefore it converts variable names. Here I changed it to CamelCasePropertyNamingStrategy
.
import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.fasterxml.jackson.core.JsonGenerator.Feature
import com.fasterxml.jackson.databind.ObjectMapper
import com.twitter.finatra.json.modules.FinatraJacksonModule
import com.twitter.finatra.json.utils.CamelCasePropertyNamingStrategy
object CustomJacksonModule extends FinatraJacksonModule {
override val serializationInclusion = Include.ALWAYS
override val propertyNamingStrategy = CamelCasePropertyNamingStrategy
override def additionalMapperConfiguration(mapper: ObjectMapper) {
mapper.configure(Feature.WRITE_NUMBERS_AS_STRINGS, true)
}
}
In your FinatraServer class you need to override:
override def jacksonModule = CustomJacksonModule
You can check it from github too: gist