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 .

  • El método hasSystemFeature devuelve un valor incorrecto mientras se comtesting la compatibilidad con BluetoothLE
  • ¿Cómo habilitar la authentication de portador en la aplicación Spring Boot?
  • Miembro de Kotlin y extensión al mismo time
  • Recuperar respuesta JSON de rxjava / retrofit request POST
  • Pass facebook AccessToken por Retrofit
  • AAR / JAR no se genera con Android Studio 3.0 Canary 7
  • Kotlin: cadena de formatting
  • Kotlin: ¿Qué es kotlin.String! tipo
  • Parcelable con object personalizado plotble
  • search al final de todas las particiones y sobrevivir al reequilibrio automático de los consumidores de Kafka
  • ¿Qué es el object de la unidad en Kotlin