1
resposta

GSON retorna null

Executo esse método:

@Test
    public void testaJsonToClassTrades() throws ClientProtocolException, IOException {
        ClientWebservice ws = new ClientWebservice(); 
        Gson gson = new Gson();
        String json = ws.getJsonTrades(URL_WEBSERVICE);
        System.out.println(json);
        System.out.println("--------------------------------------------------");

        Ticker ticker = gson.fromJson(json, Ticker.class);
//        Ticker ticker = new ReaderJson().JsonToClass(json);   

        System.out.println(ticker);

e retorna:

{"ticker": {"high":"39982.07385000","low":"38700.00000000","vol":"203.48440316","last":"39374.92722000","buy":"39234.29085000","sell":"39374.92721000","open":"39725.24003000","date":1580852371}}
--------------------------------------------------
Ticker [high=0.0, low=0.0, vol=0.0, last=0.0, buy=0.0, sell=0.0, open=0.0, date=null]

a minha classe ticker está assim:

public class Ticker {

    private double high;

    private double low;

    private double vol;

    private double last;

    private double buy;

    private double sell;

    private double open;

    private Integer date;

   // restante do código
 // getters e setters 
// toString
1 resposta

Oi Iago Em qual aula você teve esse problema?