MutableLiveData:在Retrofit / Moshi中分配给ArrayList的问题

我正在用一个Retrofit HTTP调用来调试一个问题。 正在进行的调用是成功的,并且响应似乎与我的POJO(在这种情况下为Kotlin数据类)格式相同。 然而,在将我的POJO列表分配给Response>时似乎有一些脱节。 没有错误,而且我已经证实,答复实际上并不是错误的。 我在这里错过了什么? 你会如何去find我的MutableLiveData和我的响应之间的断开

发生断开连接的ViewModel。 调用enqueueProjectAPICall()之后,尽管响应是项目列表,但_projects仍然为空:

class ProjectBrowserViewModel(): ViewModel(){ private var projectCall: Call private val API_KEY = "whatever" //Mutable private data private val _projects = MutableLiveData<List>() private val _selectedField = MutableLiveData() //Exposed Data val projects: LiveData<List> get() = _projects val selectedField: LiveData get()=_selectedField init { projectCall = BehanceAPI.behanceService.projects(API_KEY) } fun loadProjectsFromField(fieldName: String){ projectCall=BehanceAPI.behanceService.projects(api_key = API_KEY, creativeField = fieldName) _selectedField.value = fieldName enqueueProjectAPICall() } private fun enqueueProjectAPICall(){ projectCall.enqueue(object: Callback{ override fun onResponse(call: Call, response: Response) { _isLoading.value = false _hasErrorLoadingProjects.value = false _projects.value = response?.body()?.projects } override fun onFailure(call: Call?, t: Throwable?) { //on failure stuff } }) } } 

显示来自上面的projectCall.enqueue的填充响应的调试ViewModel: 在这里输入图像说明

APIService:

 interface BehanceService{ @GET( "v2/fields") fun creativeField(@Query("api_key") api_key: String): Call @GET("v2/projects") fun projects(@Query("api_key") api_key: String, @Query("field") creativeField: String? = null, @Query("q") searchString: String? = null, @Query("time") timeCategory: String?=null, //possible values = all, today, week, month @Query("country") countryFIPSCode: String?=null, @Query("state") stateOrProvinceName: String? = null, @Query("city") cityName: String? = null, @Query("page") pageNumber: Number? = null, @Query("tags") listOfTagNames: String? = null, @Query("color_hex") rgbHexValue: String? = null, @Query("color_range") rangeFromRGBHex: Int? = null, @Query("license") licenseAcronymFromCC: String? = null //acceptable values found here: http://creativecommons.org/licenses/ ): Call } 

API对象:

 object BehanceAPI { private val BASE_URL = "http://www.behance.net/" val retrofittedBuilder: Retrofit by lazy { Retrofit.Builder().baseUrl(BASE_URL) .addConverterFactory(MoshiConverterFactory.create()) .build() } val behanceService: BehanceService = retrofittedBuilder.create(BehanceService::class.java) } 

模型:

 data class ProjectResponse( @Json(name = "projects") val projects: List, @Json(name = "http_code") val httpCode: Int //200 ) data class Project( @Json(name = "id") val id: Int, //32761543 @Json(name = "name") val name: String, //Cana @Json(name = "published_on") val publishedOn: Int, //1453743936 @Json(name = "created_on") val createdOn: Int, //1452473817 @Json(name = "modified_on") val modifiedOn: Int, //1517950825 @Json(name = "url") val url: String, //https://www.behance.net/gallery/32761543/Cana @Json(name = "privacy") val privacy: String, //public @Json(name = "fields") val fields: List, @Json(name = "covers") val covers: Covers, @Json(name = "mature_content") val matureContent: Int, //0 @Json(name = "mature_access") val matureAccess: String, //allowed @Json(name = "owners") val owners: List, @Json(name = "stats") val stats: Stats, @Json(name = "conceived_on") val conceivedOn: Int, //1452470400 @Json(name = "features") val features: List, @Json(name = "colors") val colors: List ) data class Feature( @Json(name = "featured_on") val featuredOn: Int, //1516231826 @Json(name = "site") val site: Site, @Json(name = "url") val url: String //https://www.behance.net/galleries/6/Product-Design ) data class Site( @Json(name = "id") val id: Int, //19 @Json(name = "parent_id") val parentId: Int, //6 @Json(name = "name") val name: String, //Product Design @Json(name = "key") val key: String, //furniture @Json(name = "icon") val icon: String, //https://a5.behance.net/003a0da718aa53cfec3276910bf05c4ce98c382d/img/galleries/icons/square/1x/gallery-6.png?cb=264615658 @Json(name = "app_icon") val appIcon: String, //?cb=264615658 @Json(name = "domain") val domain: String, //furnitureserved.com @Json(name = "url") val url: String, //https://www.behance.net/galleries/6/Product-Design @Json(name = "ribbon") val ribbon: Ribbon ) data class Ribbon( @Json(name = "image") val image: String, //https://a5.behance.net/003a0da718aa53cfec3276910bf05c4ce98c382d/img/shared_icons/png/1x/ribbons/product-design.png?cb=264615658 @Json(name = "image_2x") val image2x: String //https://a5.behance.net/003a0da718aa53cfec3276910bf05c4ce98c382d/img/shared_icons/png/2x/ribbons/product-design.png?cb=264615658 ) data class Owner( @Json(name = "id") val id: Int, //2723641 @Json(name = "first_name") val firstName: String, //Marlon @Json(name = "last_name") val lastName: String, //Motta @Json(name = "username") val username: String, //marlonmotta @Json(name = "city") val city: String, //Bauru @Json(name = "state") val state: String, @Json(name = "country") val country: String, //Brazil @Json(name = "location") val location: String, //Bauru, Brazil @Json(name = "company") val company: String, @Json(name = "occupation") val occupation: String, //Product Designer @Json(name = "created_on") val createdOn: Int, //1368771073 @Json(name = "url") val url: String, //https://www.behance.net/marlonmotta @Json(name = "images") val images: Images, @Json(name = "display_name") val displayName: String, //Marlon Motta @Json(name = "fields") val fields: List, @Json(name = "has_default_image") val hasDefaultImage: Int, //0 @Json(name = "website") val website: String, @Json(name = "stats") val stats: UserStats ) data class Images( @Json(name = "50") val x50: String?, //https://mir-s3-cdn-cf.behance.net/user/50/bdedf92723641.55c54fed7493e.jpg @Json(name = "100") val x100: String?, //https://mir-s3-cdn-cf.behance.net/user/100/bdedf92723641.55c54fed7493e.jpg @Json(name = "115") val x115: String?, //https://mir-s3-cdn-cf.behance.net/user/115/bdedf92723641.55c54fed7493e.jpg @Json(name = "230") val x230: String?, //https://mir-s3-cdn-cf.behance.net/user/230/bdedf92723641.55c54fed7493e.jpg @Json(name = "138") val x138: String?, //https://mir-s3-cdn-cf.behance.net/user/138/bdedf92723641.55c54fed7493e.jpg @Json(name = "276") val x276: String? //https://mir-s3-cdn-cf.behance.net/user/276/bdedf92723641.55c54fed7493e.jpg ) data class UserStats( @Json(name = "followers") val followers: Int, //544 @Json(name = "following") val following: Int, //1509 @Json(name = "appreciations") val appreciations: Int, //1200 @Json(name = "views") val views: Int, //11287 @Json(name = "comments") val comments: Int //83 ) data class Stats( @Json(name = "views") val views: Int, //2386 @Json(name = "appreciations") val appreciations: Int, //240 @Json(name = "comments") val comments: Int //13 ) data class Color( @Json(name = "h") val h: Double, //0.166667 @Json(name = "s") val s: Double, //0.00411523 @Json(name = "v") val v: Double, //0.952941 @Json(name = "r") val r: Int, //243 @Json(name = "g") val g: Int, //243 @Json(name = "b") val b: Int //242 ) data class Covers( @Json(name = "404") val x404: String, //https://mir-s3-cdn-cf.behance.net/projects/404/cb77e332761543.Y3JvcCwxMjEyLDk0OSw5NCww.png @Json(name = "202") val x202: String, //https://mir-s3-cdn-cf.behance.net/projects/202/cb77e332761543.Y3JvcCwxMjEyLDk0OSw5NCww.png @Json(name = "230") val x230: String, //https://mir-s3-cdn-cf.behance.net/projects/230/cb77e332761543.Y3JvcCwxMjEyLDk0OSw5NCww.png @Json(name = "115") val x115: String, //https://mir-s3-cdn-cf.behance.net/projects/115/cb77e332761543.Y3JvcCwxMjEyLDk0OSw5NCww.png @Json(name = "original") val original: String //https://mir-s3-cdn-cf.behance.net/projects/original/cb77e332761543.Y3JvcCwxMjEyLDk0OSw5NCww.png )