Volley not functioning in kotlin like it was working in java


#1

I am trying to integrated a volley request of JSONObjectRequest in Kotlin

 var requestToRegisterUser = JsonObjectRequest(Request.Method.POST,BASE_URL +        USER_REGISTRATION , bodyParams,
            Response.Listener { response ->
                toast(response.toString())

            },
            Response.ErrorListener { error ->
                toast(error.toString())
            })
{
override fun getHeaders() : Map<String,String> {
  }
}

And it says
modifier override is not applicable to local function

On the other end I am able to use it StringRequest

val sessionRequest = object : StringRequest(Request.Method.GET, BASE_URL, Response.Listener { s ->
        doCallForWhoAmI()
    }, Response.ErrorListener { e ->

    }) {
        override fun parseNetworkResponse(response: NetworkResponse?): Response<String> {
            Log.i("response", response.toString())
            val cookiesInfo : java.util.TreeMap<String,String> = response?.headers as TreeMap<String, String>
            val cookie = cookiesInfo.get("Set-Cookie")

            var prefHandler = PreferenceHandler(this@SplashActivity)
            prefHandler.saveSession(cookie as String)

            return super.parseNetworkResponse(response)
        }
    }

Like these but instead of method parseNetworkResponse I want to use getHeaders Method to attach some values at post request.


#2

you should declare your first val same as the second one with object : … .
in the first declaration you simply create a new instance of JsonObjectRequest whereas in the second delcaration you define an instance of a class which inherits from StringRequest which in turn can override any open method in its parent class.


#3

Can you please show me by some code if you have done it with.

I am trying that block but it seems it is not looking like it.


#4
var requestToRegisterUser = object : JsonObjectRequest(Request.Method.POST,BASE_URL +        USER_REGISTRATION , bodyParams,
            Response.Listener { response ->
                toast(response.toString())

            },
            Response.ErrorListener { error ->
                toast(error.toString())
            })
{
override fun getHeaders() : Map<String,String> {
  }
}