Closed yzheka closed 1 year ago
This doesn't have to be built into Moshi core to be doable. Check out the Wrapped adapter here: https://github.com/serj-lotutovici/moshi-lazy-adapters
@ZacSweers looks almost like I suggest but not. There we declare the path we want to pick fom response inside Retrofit interface method. But I suggest to parse json into custom class structure. This can improve creating POJO for json like this:
{
"keyA"{
"keyB":{
"keyC":{
"keyD":"someValue"
}
}
},
"keyB":"someValue"
}
with this feature no need to create lots of classes. Just one class where with 2 properties:
data class SomeData(
@Json("keyA.keyB.keyC.keyD") val keyD:String, // or @Json("keyA.keyB.keyC") because wee already declared val keyD
@Json("keyB") val keyB:String //works like always
)
The linked Wrapped adapter above does exactly what you're asking for, please read it.
@ZacSweers sorry, I can't find it in docs. can you point me to it please? I see how it is used with retrofit, but my idea to use it as json parser without retrofit.
Let's say we have some complex json like this
Would be grat to have a feature to convert it to