algolia / algoliasearch-client-kotlin

⚡️ A fully-featured and blazing-fast Kotlin/Android API client to interact with Algolia.
https://www.algolia.com/doc/api-client/getting-started/install/kotlin/
MIT License
59 stars 23 forks source link

Set attribute to `null` in partial update #402

Closed mleonhard-flexport closed 1 year ago

mleonhard-flexport commented 1 year ago

Is your feature request related to a problem? Please describe 🙏 We have a nullable attribute that we wish to write to an Algolia index. Our code must use partialUpdateObjects. We need a way to delete an attribute or set its value to null. Unfortunately, the current version of the library (v2.1.5) does not provide a way to create a Partial.Update object with a null value.

val value: String? = null
// Type mismatch: required String, found String?.
val update1 = Partial.Update(Attribute("attr1"), value)
// None of the following functions can be called with the arguments supplied.
// <init>(Attribute, Boolean) defined in com.algolia.search.model.indexing.Partial.Update
// <init>(Attribute, Number) defined in com.algolia.search.model.indexing.Partial.Update
// <init>(Attribute, String) defined in com.algolia.search.model.indexing.Partial.Update
// <init>(Attribute, JsonArray) defined in com.algolia.search.model.indexing.Partial.Update
// <init>(Attribute, JsonObject) defined in com.algolia.search.model.indexing.Partial.Update
val update2 = Partial.Update(Attribute("attr1"), null)

Describe the solution you'd like 🤔 Add constructors:

public constructor(attribute: Attribute, value: JsonNull)
public constructor(attribute: Attribute, value: String?)
public constructor(attribute: Attribute, value: Boolean?)
public constructor(attribute: Attribute, value: Number?)
public constructor(attribute: Attribute, value: JsonArray?)
public constructor(attribute: Attribute, value: JsonObject?)

Describe alternatives you've considered ✨ I considered writing an empty string. This will require extra work to change the code that reads the index.

Additional context