-
Notifications
You must be signed in to change notification settings - Fork 496
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
[FEATURE]建议NameFilter.process(...)
方法签名传入Field/FieldInfo
#484
Labels
enhancement
New feature or request
Milestone
Comments
vergilyn
changed the title
[FEATURE]建议
[FEATURE]建议Jun 17, 2022
NameFilter.process(...)
扩展传入FieldInfo等信息。NameFilter.process(...)
方法签名传入Field/FieldInfo
wenshao
added a commit
that referenced
this issue
Jun 17, 2022
wenshao
added a commit
that referenced
this issue
Jun 17, 2022
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.8-SNAPSHOT/ package com.alibaba.fastjson2.filter;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.PropertyNamingStrategy;
import com.alibaba.fastjson2.annotation.JSONField;
import com.alibaba.fastjson2.util.BeanUtils;
import org.junit.jupiter.api.Test;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ContextVNameFilterTest {
@Test
public void test() throws Exception {
Bean bean = new Bean();
bean.id = 10;
AtomicReference<BeanContext> contextReference = new AtomicReference<>();
ContextNameFilter filter = (BeanContext context, Object object, String name, Object value) -> {
contextReference.set(context);
return BeanUtils.fieldName(name, PropertyNamingStrategy.KebabCase.name());
};
assertEquals("{\"user-id\":10}", JSON.toJSONString(bean, filter));
BeanContext context = contextReference.get();
assertEquals(Bean.class, context.getBeanClass());
assertEquals(int.class, context.getFieldClass());
assertEquals(int.class, context.getFieldType());
assertEquals(Bean.class.getField("id"), context.getField());
assertEquals("userId", context.getAnnotation(JSONField.class).name());
assertEquals(null, context.getFormat());
assertEquals(null, context.getLabel());
assertEquals(0, context.getFeatures());
}
public static class Bean {
@JSONField(name = "userId")
public int id;
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
请描述您的需求或者改进建议
需求:
部分java-bean中的boolean类型属性或者
isSucceess()
方法,序列化时json-key强制命名成isSuceess
(默认key命名是success
)。(不期望 通过
JSONField
单独指定。或者是否还有别的更好的建议?)建议,
NameFilter.process(...)
扩展传入FieldInfo等信息。(当前方法签名NameFilter > process(Object object, String name, Object value)
。)否则,可能需要再次通过反射去获取FieldInfo。
请描述你建议的实现方案
传入与 name 对应的
Field
和FieldInfo
。描述您考虑过的替代方案
附加信息
The text was updated successfully, but these errors were encountered: