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 字符串是否没有详细区分?PropertyNamingStrategy #2459

Closed
8502596 opened this issue Apr 18, 2024 · 7 comments
Closed

转换json 字符串是否没有详细区分?PropertyNamingStrategy #2459

8502596 opened this issue Apr 18, 2024 · 7 comments
Assignees
Labels
bug Something isn't working fixed
Milestone

Comments

@8502596
Copy link

8502596 commented Apr 18, 2024

新手不懂就问 如下代码 Jdk 21 graalvm , fastjson2 2.0.49

`
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.PropertyNamingStrategy;
import com.alibaba.fastjson2.annotation.JSONType;
import lombok.Data;
@DaTa
@jsontype(naming= PropertyNamingStrategy.LowerCase)
public class User {

private  String username ;
private  String password ;

public static void main(String[] args) {
    User user=new User();
    user.setUsername("11111");
    user.setPassword("password");

    System.out.println(JSON.toJSONString(user));
}

}

`
image

虽然我知道 修改如下 代码 去掉 @jsontype 即可正常

System.out.println(JSON.toJSONString(user, NameFilter.of(PropertyNamingStrategy.LowerCase)));

仍不能解释疑惑 为什么 这个枚举例如
@jsontype(naming= PropertyNamingStrategy.UpperCase)
@jsontype(naming= PropertyNamingStrategy.PascalCase)
@jsontype(naming= PropertyNamingStrategy.CamelCase)
...
这些 使用 System.out.println(JSON.toJSONString(user)); 正常 而LowerCase 却是不行 其他很多未测试 请大佬释疑

@8502596 8502596 added the bug Something isn't working label Apr 18, 2024
@8502596
Copy link
Author

8502596 commented Apr 19, 2024

查看源码跟踪调试 发现 Utils->BeanUtils.java getterName 少了对应的 处理
image

红圈中 LowerCase 是我加上的,不知少了相关 PropertyNamingStrategy 里面的其他类型 是何意啊?

@wenshao
Copy link
Member

wenshao commented Apr 19, 2024

你来提交一个PR?

@8502596
Copy link
Author

8502596 commented Apr 19, 2024

sorry 新手瞎鼓捣的 不太会啊 还请大佬解决呗

@wenshao
Copy link
Member

wenshao commented Apr 20, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.50-SNAPSHOT/
问题已修复,请帮忙用2.0.50-SNAPSHOT版本验证

@8502596
Copy link
Author

8502596 commented Apr 24, 2024

同理 他也应该出现在 setterName 中
@jsontype(naming= PropertyNamingStrategy.LowerCase)
System.out.println(json.toJavaObject(User.class));

请继续修正 @wenshao

@yanxutao89
Copy link
Collaborator

同理 他也应该出现在 setterName 中 @jsontype(naming= PropertyNamingStrategy.LowerCase) System.out.println(json.toJavaObject(User.class));

请继续修正 @wenshao

谢谢提醒

@wenshao
Copy link
Member

wenshao commented May 12, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.50
2.0.50已发布,请用新版本

@wenshao wenshao closed this as completed May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants