Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON.toJavaObject 转换 java.util.Currency 失败 #349

Closed
wenbinye opened this issue Jun 9, 2015 · 1 comment
Closed

JSON.toJavaObject 转换 java.util.Currency 失败 #349

wenbinye opened this issue Jun 9, 2015 · 1 comment

Comments

@wenbinye
Copy link

wenbinye commented Jun 9, 2015

使用 JSON.parseObject 可以解析 java.util.Currency 类型,但是 JSON.toJavaObject 无法转换类型:

public class JSONTest {
    public static class Money {
        public Currency currency;
        public BigDecimal amount;

        @Override
        public String toString() {
            return "Money{currency=" + currency + ", amount=" + amount + '}';
        }
    }

    @Test
    public void testJson() throws Exception {
        Money money = new Money();
        money.currency = Currency.getInstance("CNY");
        money.amount = new BigDecimal("10.03");

        String json = JSON.toJSONString(money);
        System.out.println("json = " + json);

        Money moneyBack = JSON.parseObject(json, Money.class);
        System.out.println("money = " + moneyBack);

        JSONObject jsonObject = JSON.parseObject(json);
        Money moneyCast = JSON.toJavaObject(jsonObject, Money.class);
        System.out.printf("money = " + moneyCast);
    }
}

这个是不是也需要支持一下?

wenshao added a commit that referenced this issue Apr 13, 2016
wenshao added a commit that referenced this issue Apr 13, 2016
wenshao added a commit that referenced this issue Apr 13, 2016
@wenshao wenshao added this to the 1.1.49.android milestone Apr 13, 2016
@wenshao
Copy link
Member

wenshao commented Apr 13, 2016

bug fixed. included in 1.1.49.android & 1.2.9

@wenshao wenshao closed this as completed Apr 13, 2016
wenshao added a commit that referenced this issue Jul 17, 2019
wenshao added a commit that referenced this issue Jul 17, 2019
asa1997 pushed a commit to Be-Secure/fastjson that referenced this issue Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants