Changing the Default Product Structure in Kotlin SDK

The following is what the default product structure looks like according to the Dynamic Yield product feed structure:

Open class DefaultRecsProductData : RecsProductData() { 
    var product_type: ProductType? = null 
    var group_id: String? = null 
    var name: String? = null 
    var url: String? = null 
    var price: Float? = null 
    var in_stock: Boolean? = null 
    var image_url: String? = null 
    var categories: List<String?>? = null 
    var keywords: List<String?>? = null 
} 

Changing the default using Kotlin SDK

To add more fields to the product structure:

  1. Create a new class that inherits from RecsProductData and annotate the class with the @Serializable annotation (org.jetbrains.kotlinx:kotlinx-serialization-json).
@Serializable 
class CustomRecsProductData : RecsProductData() { 
    val color: String? = null 
} 
  1. Set this class as the new default product data structure by calling setDefaultProductDataType().
private fun changeTheDefaultRecsProductData() { 
    DYSdk.getInstance().setDefaultProductDataType(CustomRecsProductData.serializer()) 
}  
  1. After calling setDefaultProductDataType(), whenever chooseVariations is called for recommendations campaigns, the return value includes the fields you added to the new class.