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

大佬能不能增加,Bean里设定了字段Json返回空的时候赋值个默认值,比如String字段是null的时候转换成空字符串"",int换0 #46

Closed
337077418 opened this issue Jul 17, 2024 · 4 comments
Labels
question Further information is requested

Comments

@337077418
Copy link

Question Description [Required]

或者说大佬你已经做了我没发现用法?
我测试好像目前都是遇到null字段都会跳过解析
我的json:

{"code":1,"msg":"","data":{"order":{"id":1863,"number":"2024070618060434152","customer_id":null,"produce_cate_code":10000,"product_id":2295,"state":4,"pay_status":null,"store_name":"测试组织三","customer_name":null,"product_name":"测试123456789","linkman":null,"mobile":null,"contacts":null,"contacts_mobile":null,"run":null,"order_type":1,"agency_name":"测试三组","agency_admin_name":null,"agency_owner_name":"测试三组","agency_owner_admin_name":"测试管理员","money":"25.00","start_time":"2024-07-06","end_time":"2026-07-05","create_time":"2024-07-06","address":"测试11111111111111111111111111","unit":"月","peer_price":"0.10","order_state_name":"作废","pay_state_name":"待处理"},"auth":[]}}

Is the issue mentioned in the framework documentation? [Required]

No

Did you consult the framework documentation but couldn't find a solution? [Required]

Yes

Has a similar issue been reported in the issue list? [Required]

No

Have you searched the issue list but couldn't find a solution? [Required]

Yes

@337077418 337077418 added the question Further information is requested label Jul 17, 2024
@337077418
Copy link
Author

image
image
跑完得到的是所有null的参数都被跳过
{
"code": 1,
"data": {
"auth": [],
"order": {
"address": "测试11111111111111111111111111",
"agency_name": "测试三组",
"agency_owner_admin_name": "测试管理员",
"agency_owner_name": "测试三组",
"create_time": "2024-07-06",
"end_time": "2026-07-05",
"id": 1863,
"money": "25.00",
"number": "2024070618060434152",
"order_state_name": "作废",
"order_type": 1,
"pay_state_name": "待处理",
"peer_price": "0.10",
"produce_cate_code": 10000,
"product_id": 2295,
"product_name": "测试123456789",
"start_time": "2024-07-06",
"state": 4,
"store_name": "测试组织三",
"unit": "月"
}
},
"msg": ""
}

@getActivity
Copy link
Owner

你直接在类的字段上面定义一个默认值,当后台没有返回这个字段的时候,或者返回为 null 的时候,框架会跳过解析和赋值,这个时候字段上面的值还是你当时给的那个。

@15110052956
Copy link

大佬,我能在整个解析过程中,获取到一个我在JavaBean中未定义的属性值吗?比如后端返回的结构体中统一增加了一个tr的字段,但是我所有的Java Bean (Data Class)都没有定义这个字段,按照Gson的解析流程会将未定义的字段都过滤掉,但是我这时想要拿到这个tr字段,应该如何做呢?

@getActivity
Copy link
Owner

@15110052956 你这个是另外的问题,需要提一个新的 issue,不要在其他人的 issue 下留言。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants