LIRAN Y
11/17/2022, 7:25 PMimport com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
data class InsideList(
@JsonProperty("price") val price: String,
@JsonProperty("product") val product: String
)
data class NList(
@JsonProperty("listexample") val listexample: List<InsideList>?
)
the response
is the json list
val jsonResponse = MapperUtility.jsonMapper.readValue<NList>(response)
println("Response : {${jsonResponse.listexample}}")
the print is:
NList(listexample=[InsideList(product=apple, price=ten)])
how can i print just the value of the product?
i tried to do it with forEach
but not works as expected 🙄Roukanken
11/17/2022, 7:42 PMmap
function (or it's various alternatives) - it allows you to transform a list to a new one, by applying a function to each element:
val prices: List<String>? = jsonResponse.listexample?.map { it.price }
LIRAN Y
11/17/2022, 7:48 PM