2

I am getting data from gemfire

List<String> objects = restTemplate.getForObject(geodeURL+"/gemfire-api/v1/queries/adhoc?q=SELECT * FROM /region s",List.class);

which is like below:

[('price':'119','volume':'20000','pe':'0','eps':'4.22','week53low':'92','week53high':'134.4','daylow':'117.2','dayhigh':'119.2','movingav50day':'115','marketcap':'0','time':'2015-11-25 05:13:34.996'), ('price':'112','volume':'20000','pe':'0','eps':'9.22','week53low':'92','week53high':'134.4','daylow':'117.2','dayhigh':'119.2','movingav50day':'115','marketcap':'0','time':'2015-11-25 05:13:34.996'), ('price':'118','volume':'20000','pe':'0','eps':'1.22','week53low':'92','week53high':'134.4','daylow':'117.2','dayhigh':'119.2','movingav50day':'115','marketcap':'0','time':'2015-11-25 05:13:34.996')]

This is a list of String I am getting.Currently I have 3 values in list.

I have a pojo class like below:

public class StockInfo {

//  @Id 
    @JsonProperty("symbol")
    private String symbol;

    @JsonProperty("price")
    private String price;

    @JsonProperty("volume")
    private String volume;

    @JsonProperty("pe")
    private String pe;

    @JsonProperty("eps")    
    private String eps;

    @JsonProperty("week53low")
    private String week53low;

    @JsonProperty("week53high")
    private String week53high;

    @JsonProperty("daylow")
    private String daylow;

    @JsonProperty("dayhigh")
    private String dayhigh;

    @JsonProperty("movingav50day")
    private String movingav50day;

    @JsonProperty("marketcap")
    private String marketcap;

    @JsonProperty("time")
    private String time;

    private String getSymbol() {
        return symbol;
    }
    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }
    public String getPrice() {
        return price;
    }
    public void setPrice(String price) {
        this.price = price;
    }
    public String getVolume() {
        return volume;
    }
    public void setVolume(String volume) {
        this.volume = volume;
    }
    public String getPe() {
        return pe;
    }
    public void setPe(String pe) {
        this.pe = pe;
    }
    public String getEps() {
        return eps;
    }
    public void setEps(String eps) {
        this.eps = eps;
    }
    public String getWeek53low() {
        return week53low;
    }
    public void setWeek53low(String week53low) {
        this.week53low = week53low;
    }
    public String getWeek53high() {
        return week53high;
    }
    public void setWeek53high(String week53high) {
        this.week53high = week53high;
    }
    public String getDaylow() {
        return daylow;
    }
    public void setDaylow(String daylow) {
        this.daylow = daylow;
    }
    public String getDayhigh() {
        return dayhigh;
    }
    public void setDayhigh(String dayhigh) {
        this.dayhigh = dayhigh;
    }
    public String getMovingav50day() {
        return movingav50day;
    }
    public void setMovingav50day(String movingav50day) {
        this.movingav50day = movingav50day;
    }
    public String getMarketcap() {
        return marketcap;
    }
    public void setMarketcap(String marketcap) {
        this.marketcap = marketcap;
    }
    public String getTime() {
        return time;
    }
    public void setTime(String time) {
        this.time = time;
    }

How do I create a List of StockInfo class object from the value I am getting from restTemplate.getForObject

1 Answer 1

1

I think you could just use:

List<StockInfo> objects = restTemplate.getForObject(geodeURL+"/gemfire-api/v1/queries/adhoc?q=SELECT * FROM /region s",List.class);
Sign up to request clarification or add additional context in comments.

4 Comments

I don't understand what you mean. Your rest call returns an array of objects, so you'll need to create an array of StockInfo. if you want an individual object you could loop over the array and find the right object.
This logic doesnt work.Just imagine how will you navigate to each value of object and assign the 'stockinfo' set values
i'm sorry, I didn't notice that the json you are getting isn't valid. Why do you get this weird representation?
Have you configured gemfire correctly to return a normal Json value?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.