基本上我有一个数据类
data class House(
val bedroom: Bedroom,
val livingroom: Livingroom
)
data class Bedroom(
val bed: String,
val pillows: List<String>
)
data class Livingroom(
val sofa: String,
val tv: String
)
我想知道如何将House
数据模型映射到只有一层的地图:
{
bed = "some-bed",
pillows = ["pillow-a", "pillow-b", "pillow-c"],
sofa = "some-sofa",
tv = "some-tv"
}
我通过首先将其转换为 json 然后映射来尝试 gson,但它会给我嵌套的地图