我无法通过Jackson转换器进行翻新发布数据。请求正文始终为空。
这是我的代码。通话方式:
@POST("mood")
fun getMoods(@Body body: MoodsRequestBody): Call<List<String>>
请求正文类:
internal data class MoodsRequestBody(val userId: String, val thought: String)
Api实例:
private val client = OkHttpClient.Builder()
.apply {
if (BuildConfig.DEBUG) addInterceptor(CurlLoggingInterceptor())
}
.build()
private val mapper = jacksonObjectMapper()
.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES,
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT,
DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
private val retrofit = Retrofit.Builder()
.baseUrl("http://<base url here>")
.client(client)
.addConverterFactory(JacksonConverterFactory.create(mapper))
.build()
private val api: Api = retrofit.create(Api::class.java)
这是我在日志中得到的卷曲:
curl -X POST --data $'{}' "http://<base url here>/mood"
如您所见,请求的主体为空。我认为它没有被序列化。请帮助。