Gson到POJO,如何读取内部JSON对象作为同一个POJO的一部分?

时间:2015-06-21 22:12:35

标签: java json gson

我有JSON,如下所示,并希望使用Gson将其转换为一个POJO

我试图弄清楚如何基本上减少内部嵌套对象,如desc,将其视为同一Java对象的一部分,而不是创建一个名为Desc的新POJO。

有没有办法用Serialized Names来查看嵌套的JSON对象?

提前致谢!

要转换为POJO的JSON

        {
            'name': name,
            'desc': {
                'country': country,
                'city': city,
                'postal': postal,
                'street': street,
                'substreet': substreet,
                'year': year,
                'sqm': sqm
            },
            'owner': [owner],
            'manager': [manager],

            'lease': {
                'leasee': [
                    {
                        'userId': leaseeId,
                        'start': leaseeStart,
                        'end': leaseeeEnd
                    }
                ],
                'expire': leaseExpire,
                'percentIncrease': leasePercentIncrease,
                'dueDate': dueDate
            },
            'deposit': {
                'bank': 'Sample Bank',
                'description': 'This is a bank'
            }
        }

自定义POJO

public class Asset {

private String mId;

@SerializedName("name")
private String mName;

private String mCountry;

private String mCity;

private String mPostal;

private String mStreet;

private String mSubstreet;

private int mYear;

private int mSqm;

@SerializedName("owner")
private List<String> mOwners;

@SerializedName("manager")
private List<String> mManagers;

private List<Leasee> mLeasees;

private DateTime mLeaseExpiration;

private int mPercentIncrease;

private int mDueDate;

private String mDepositBank;

private String mDepositDescription;

}

0 个答案:

没有答案