Не удалось прочитать ошибку HTTP-сообщения из-за передачи нулевого значения в id: spring-boot, kotlin, mongodb - PullRequest
0 голосов
/ 29 февраля 2020

Я совершенно новичок в kotlin программировании и пн go дБ. Я определяю класс данных, для которого все поля данных не обнуляемы и все поля val

data class Order( @Id
                  val id: String,
                  val customerId: String,
                  val externalTransactionId : String,
                  val quoteId :String,
                  val manifestItems : List<ManifestItem>,
                  val externalTokenNumber : String,
                  val deliveryId : String,
                  val quoteCreatedTime: String,
                  val deliveryCreatedTime: String,
                  val status : String,
                  val deliveryInfo: DeliveryInfo,
                  val pickupInfo: PickupInfo,
                  val riderId : String,
                  val currency : String,
                  val expiryTime : String,
                  val trackingUrl : String,
                  val complete:Boolean,
                  val updated:String
) 

и я отправляю http-запрос со следующим телом

{

    "pickupAddress":"101 Market St, San Francisco, CA 94105",
    "deliveryAddress":"101 Market St, San Francisco, CA 94105",
    "deliveryExpectedTime":"2018-07-25T23:31:38Z",
    "deliveryAddressLatitude":7.234,
    "deliveryAddressLongitude":80.000,
    "pickupLatitude":7.344,
    "pickupLongitude":8.00,
    "pickupReadyTime":""

} 

в моем классе маршрутизатора. Я получаю тело запроса для заказа объекта и отправки в сервисный класс

  val request = serverRequest.awaitBody<Order>()
  val quoteResponse =  quoteService.createQuote(request,customerId)

в моем сервисном классе я сохраняю заказ в базе данных

 suspend fun createQuote(order: Order,customerId:String):QuoteResponse {
        ordersRepo.save(order).awaitFirst()
           //generating quote response here
        return quoteResponse
}

в базе данных генерируется id . У меня такая ошибка при отправке запроса

org.springframework.web.server.ServerWebInputException: 400 BAD_REQUEST "Failed to read HTTP message"; nested exception is org.springframework.core.codec.DecodingException: JSON decoding error: Instantiation of [simple type, class basepackage.repo.Order] value failed for JSON property id due to missing (therefore NULL) value for creator parameter id which is a non-nullable type; nested exception is com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class basepackage.repo.Order] value failed for JSON property id due to missing (therefore NULL) value for creator parameter id which is a non-nullable type
 at [Source: (org.springframework.core.io.buffer.DefaultDataBuffer$DefaultDataBufferInputStream); line: 12, column: 1] (through reference chain: basepackage.repo.Order["id"])

Как мне решить эту проблему.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...