[InstantSearch-iOS] Set decoding strategy to HitsInteractor

I want my Codable model variable names to be in camel case however when I use it with HitsInteractor it’s on snake case by default

// { "first_name": "sample" }

// This works because the property name is on snake case similar with json
struct Person: Codable  {
 var first_name

// This doesn't work unless I add CodingKeys
struct Person: Codable  {
   var firstName

   private enum CodingKeys: String, CodingKey {
      case firstName = "first_name"

// Usage
var personInteractor: HitsInteractor<Hit<Person>> 

Is there a way I could set the HitsInteractor 's JsonDecoder.keyDecodingStrategy so I don’t need to add CodingKeys per model? If yes, how and where? Can’t seem to find the api for this. Thanks!

Hi @Tef ,

There’s currently no way to configure the JsonDecoder for HitsInteractor. We’ve added it as a feature request for the library.

1 Like

It’s possible starting from the version 7.21.0 of the InstantSearch iOS.
There is a new jsonDecoder parameter in the HitsInteractor constructor.
The expected usage looks as follows:

let snakeCaseDecoder = JSONDecoder()
snakeCaseDecoder.keyDecodingStrategy = .convertFromSnakeCase

let hitsInteractor = HitsInteractor<Hit<Person>>(jsonDecoder: snakeCaseDecoder)
1 Like