将对象与JSON相互转换

时间:2018-09-15 17:59:43

标签: java json rest spring-boot

也许有人可以帮助我,并告诉对象对象结构是成功进行JSON这样的成功转换的原因?

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

我尝试创建对象,但是没有用:

public enum Currency {
    USD,
    BYN;
}

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

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

我在哪里错了?

1 个答案:

答案 0 :(得分:1)

Converted类中使用以下内容:

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

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

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