I'm trying to write a toString() method for a class that has a inner class inside it, and I'm having trouble with that. I was thinking about looping through each array, but I didn't do it correctly. Any suggestions would be great.
public class MarketDataListLevel2 {
public static class BidAskList {
protected MarketData Bid;
protected MarketData Ask;
private BidAskList(@JsonProperty("Bid") MarketData Bid, @JsonProperty("Ask") MarketData Ask) {
this.Bid = Bid;
this.Ask = Ask;
}
}
protected BidAskList[] BidAskList;
public MarketDataListLevel2(@JsonProperty("Top10BidAsks") BidAskList[] BidAskList) {
this.BidAskList = BidAskList;
}
public String toString() {
// Will make an edit to this later
}
}
MarketData is essentially an object with 4 fields.
EDIT:
This is the sort of data that I want outputted:
{"Top10BidAsks":[ {"Bid":{"Price":10.0,"Size":2.0,"ExchangeID":"SMART","timeStamp":0}, "Ask":{"Price":12.0,"Size":2.0,"ExchangeID":"SMART","timeStamp":0}}, {"Bid":{"Price":0.0,"Size":0.0,"ExchangeID":"SMART","timeStamp":0}, "Ask":{"Price":13.0,"Size":12.0,"ExchangeID":"SMART","timeStamp":0}}] }
As you can see a {"Price":10.0,"Size":2.0,"ExchangeID":"SMART","timeStamp":0} is essentially 4 fields constructed from my MarketData class.
The bid and ask is essentially one object (inner class created from being made up of two Marketdata objects). And finally, the entire object is the MarketDataListLevel2 class.
Basically I want my toString method to be able to output data, that involves all 3 of these classes.