CopKubar
CopKubar

Reputation: 29

Converting Object to and from JSON

Maybe someone help me and tell which structure of object should be for successful converting to and from JSON like this?

{"converted":{"BYN":  {"amount":  "753.48",  "currency":  "BYN"},  "USD":  {"amount":  "350.00",  "currency":  "USD"}}}   

I have tried create object but it did not work:

public enum Currency {
    USD,
    BYN;
}

public class CurrencyInfo {
    private Double amount;
    private Currency currency;
} 

public class Converted {
    private Map<Currency, CurrencyInfo> convertedAmount;
}

Where were I wrong?

Upvotes: 1

Views: 62

Answers (1)

S.K.
S.K.

Reputation: 3697

Use following for Converted class:

class Converted {
    private Map<Currency, CurrencyInfo> converted;

    public Map<Currency, CurrencyInfo> getConverted() {
        return converted;
    }

    public void setConverted(Map<Currency, CurrencyInfo> converted) {
        this.converted = converted;
    }
}

Upvotes: 1

Related Questions