I have a java class Payment.java
which constructs the "Payment" object with 5 constructors and required setter/getters as following:
public class Payment {
//Contractors
private Double amount, fee;
private String TXID;
private int time, type;
public Payment(Double amount, Double fee, String TXID, int time, int type) {
this.amount = amount;
this.fee = fee;
this.TXID = TXID;
this.time = time;
this.type = type;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double value) {
this.amount = value;
}
public Double getFee() {
return fee;
}
public void setFee(Double value) {
this.fee = value;
}
public String getTXID() {
return TXID;
}
public void setTXID(String value) {
this.TXID = value;
}
public int getTime() {
return time;
}
public void setTime(int value) {
this.time = value;
}
public int getType() {
return type;
}
public void setType(int value) {
this.type = value;
}
}
I have another method which sends a HTTP(GET)
request to an external API and returns the results in JSON
format as a String as shown below:
{
"result" : {
"nh_wallet" : true,
"payments" : [
{
"amount" : "0.00322253",
"fee" : "0.00006577",
"TXID" : "",
"time" : 1533114558,
"type" : 1
},
{
"amount" : "0.00273396",
"fee" : "0.0000558",
"TXID" : "",
"time" : 1533029140,
"type" : 1
},
{
"amount" : "0.00284428",
"fee" : "0.00005805",
"TXID" : "",
"time" : 1532944513,
"type" : 1
},
{
"amount" : "0.00213709",
"fee" : "0.00004361",
"TXID" : "",
"time" : 1532856970,
"type" : 1
}
],
"base64MarchantID" : "366GT4q6hw7cVN6zzkFWfqZeKHHXZCp4rA"
},
"method" : "stats.provider.payments"
}
Supposing that the JSON result String is actually a dynamic <List>Payment
, what is the best way to split this String into several splitted "Payment"(s) dynamically?