Im working on my school project and im new in android programming but i have some programming experiance in c# and .net.
This is my code:
public class ProizvodiAPI {
public class ProizvodiVM implements Serializable
{
public Integer proizvodID;
public String naziv;
public String sifra;
public BigDecimal cijena;
public String jedinicaMjere;
public String vrstaProizvoda;
}
public class ProizvodiLista implements Serializable
{
public List<ProizvodiVM> proizvodi;
}
public static void GetAllProizvode(final MyRunnable<ProizvodiLista> onSuccess)
{
RequestQueue queue = Volley.newRequestQueue(MyApp.getContext());
String url = "Proizvodi/GetProizvodiVM";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, Config.urlApi + url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response)
{
final Gson gson = MyGson.build();
final ProizvodiLista model = gson.fromJson(response, ProizvodiLista.class);
onSuccess.run(model);
}
}, new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Toast.makeText(MyApp.getContext() , "That didn't work", Toast.LENGTH_LONG).show();
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
}
}
Program crashes here:
final ProizvodiLista model = gson.fromJson(response, ProizvodiLista.class);
Is the problem with deserializing json, if it is, shoud i change the Java class and what to change ?
Here is my C# class in Web Api:
public class Proizvodi
{
public int ProizvodID { get; set; }
public string Naziv { get; set; }
public string Sifra { get; set; }
public decimal Cijena { get; set; }
public string JedinicaMjere { get; set; }
public string VrstaProizvoda { get; set; }
}
And this is response: json response