Renderiza la respuesta json en Kotlin

Soy nuevo en Kotlin y Java. Intento hacer una llamada API y luego renderizarla en Kotlin.

Así es como obtengo la respuesta JSON:

[ { "AWBNo": "1326217373504", "AuthKey": "Valid", "OrderNo": "SGHRGR15073TCC", "ReturnMessage": "Successful", "ShipmentSummary": [ { "PickUpDate": "08-10-2017", "PickUpTime": "0015", "OriginLocation": "DEL/WDL, Delhi NCR, DELHI", "DestinationLocation": "", "Weight": "0", "ExpectedDeliveryDate": "10/11/2017 12:21:32 AM", "Status": "Delivenetworking", "StatusCode": "DLVD", "StatusDate": "11-10-2017", "StatusTime": "1316", "Location": "Berhampur, Berhampur, ORISSA", "Comment": "Shipment Delivenetworking by SR: RAKESH, DeliveryDate:2017-10-11 1316, Receiver Name: Manmandir Mobile Accessories Remarks : " }, { "PickUpDate": "08-10-2017", "PickUpTime": "0015", "OriginLocation": "DEL/WDL, Delhi NCR, DELHI", "DestinationLocation": "", "Weight": "0", "ExpectedDeliveryDate": "10/11/2017 12:21:32 AM", "Status": "Out for Delivery", "StatusCode": "OFD", "StatusDate": "11-10-2017", "StatusTime": "0858", "Location": "Berhampur, Berhampur, ORISSA", "Comment": "Out for delivery: 39031-RAKESH-PDS1728408582139031" } ] } ] 

¿Cómo puedo usar esto para representar en un object Java?

Entiendo que necesitamos crear una class de datos POJO similar a la respuesta que recibimos.

le agradecería si me puede mostrar una class de muestra que funcionará con esto.

Este código de class de ejemplo le proporciona un código de class de anotación de biblioteca GSON . Que puedes usar para analizar tu json.

Puedes eliminar annotations si quieres usar la class normal en Kotlin y Java.

Puede usar la class Kotlin debajo para analizar su respuesta json:

Código de class Kotlin :

Enlace: https://pastebin.com/gXq3TrXf

  class Example { @SerializedName("AWBNo") @Expose var awbNo:String @SerializedName("AuthKey") @Expose var authKey:String @SerializedName("OrderNo") @Expose var orderNo:String @SerializedName("ReturnMessage") @Expose var returnMessage:String @SerializedName("ShipmentSummary") @Expose var shipmentSummary:List<ShipmentSummary> = null inner class ShipmentSummary { @SerializedName("PickUpDate") @Expose var pickUpDate:String @SerializedName("PickUpTime") @Expose var pickUpTime:String @SerializedName("OriginLocation") @Expose var originLocation:String @SerializedName("DestinationLocation") @Expose var destinationLocation:String @SerializedName("Weight") @Expose var weight:String @SerializedName("ExpectedDeliveryDate") @Expose var expectedDeliveryDate:String @SerializedName("Status") @Expose var status:String @SerializedName("StatusCode") @Expose var statusCode:String @SerializedName("StatusDate") @Expose var statusDate:String @SerializedName("StatusTime") @Expose var statusTime:String @SerializedName("Location") @Expose var location:String @SerializedName("Comment") @Expose var comment:String } } 

Código de class Java:

Enlace: https://pastebin.com/zrPNB0T4

 public class Example { @SerializedName("AWBNo") @Expose private String aWBNo; @SerializedName("AuthKey") @Expose private String authKey; @SerializedName("OrderNo") @Expose private String orderNo; @SerializedName("ReturnMessage") @Expose private String returnMessage; @SerializedName("ShipmentSummary") @Expose private List<ShipmentSummary> shipmentSummary = null; public String getAWBNo() { return aWBNo; } public void setAWBNo(String aWBNo) { this.aWBNo = aWBNo; } public String getAuthKey() { return authKey; } public void setAuthKey(String authKey) { this.authKey = authKey; } public String getOrderNo() { return orderNo; } public void setOrderNo(String orderNo) { this.orderNo = orderNo; } public String getReturnMessage() { return returnMessage; } public void setReturnMessage(String returnMessage) { this.returnMessage = returnMessage; } public List<ShipmentSummary> getShipmentSummary() { return shipmentSummary; } public void setShipmentSummary(List<ShipmentSummary> shipmentSummary) { this.shipmentSummary = shipmentSummary; } public class ShipmentSummary { @SerializedName("PickUpDate") @Expose private String pickUpDate; @SerializedName("PickUpTime") @Expose private String pickUpTime; @SerializedName("OriginLocation") @Expose private String originLocation; @SerializedName("DestinationLocation") @Expose private String destinationLocation; @SerializedName("Weight") @Expose private String weight; @SerializedName("ExpectedDeliveryDate") @Expose private String expectedDeliveryDate; @SerializedName("Status") @Expose private String status; @SerializedName("StatusCode") @Expose private String statusCode; @SerializedName("StatusDate") @Expose private String statusDate; @SerializedName("StatusTime") @Expose private String statusTime; @SerializedName("Location") @Expose private String location; @SerializedName("Comment") @Expose private String comment; public String getPickUpDate() { return pickUpDate; } public void setPickUpDate(String pickUpDate) { this.pickUpDate = pickUpDate; } public String getPickUpTime() { return pickUpTime; } public void setPickUpTime(String pickUpTime) { this.pickUpTime = pickUpTime; } public String getOriginLocation() { return originLocation; } public void setOriginLocation(String originLocation) { this.originLocation = originLocation; } public String getDestinationLocation() { return destinationLocation; } public void setDestinationLocation(String destinationLocation) { this.destinationLocation = destinationLocation; } public String getWeight() { return weight; } public void setWeight(String weight) { this.weight = weight; } public String getExpectedDeliveryDate() { return expectedDeliveryDate; } public void setExpectedDeliveryDate(String expectedDeliveryDate) { this.expectedDeliveryDate = expectedDeliveryDate; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getStatusCode() { return statusCode; } public void setStatusCode(String statusCode) { this.statusCode = statusCode; } public String getStatusDate() { return statusDate; } public void setStatusDate(String statusDate) { this.statusDate = statusDate; } public String getStatusTime() { return statusTime; } public void setStatusTime(String statusTime) { this.statusTime = statusTime; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } } } 

Puede usar su nombre de class reemplazando el Example .

  • Cómo implementar una function de Kotlin a una vista
  • Plantilla de Facebook de spring fetchObject a PagedList
  • ¿Por qué @Primary no funciona para las classs de Kotlin a veces?
  • Instancia de class Kotlin assertEqual
  • La biblioteca de Android escrita en Kotlin, proporciona soporte para aplicaciones Java
  • Cómo get un PhoneStateListener cuando usa la funcionalidad Dual SIM
  • Cómo usar Spek
  • No se puede save el model de datos que contiene List <Model> con Room ORM Kotlin
  • ¿Accediendo a la function de extensión estática de otra class en Kotlin?
  • ¿Cómo puedo get el operador de split de Python en Kotlin?
  • En Kotlin, error de deserialization de Jackson con class de datos