Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1K
Views
How can correctly parse nested JSON Object using Retrofit 2.0 (Kotlin)?

The following JSON object is what I'm receiving from server (get request). I need to get the coordinate values (lat, long)

{
    "loc": {
        "type": "Point",
        "coordinates": [
            -47.0487786,
            -22.9001656
        ]
    },
    "city": "New Jersey",
    "name": "John Doe",
    "_id": "5c7958b3e3234b3472d9917d"
}

I'm trying do this using the following Poko (Kotlin):

package com.zowye.API.Models

import com.google.gson.annotations.SerializedName


class Salao
    (
    @SerializedName("loc") var coordinate:  , // not sure about the type
    var city: String?,
    var name: String?
)

How can I parse it? Thanks.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You should create a data class for "loc"

data class Salao(
        @SerializedName("loc")
        val location : Location,
        val city : String,
        val name : String,
        @SerializedName("_id")
        val id : String
    )

data class Location (
        val type : String,
        val coordinates : Array<Float>
    )
over 4 years ago · Santiago Trujillo Report

0

Add one more class Location which represents the tested object type.

    package com.zowye.API.Models

    import com.google.gson.annotations.SerializedName


    class Location (
        var type: String?,
        var coordinates: Float[]?
    )

    class Salao
        (
        @SerializedName("loc") var coordinate: Location,
        var city: String?,
        var name: String?
    )
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!