com.alibaba.fastjson.serializer.SimplePropertyPreFilter Java Examples
The following examples show how to use
com.alibaba.fastjson.serializer.SimplePropertyPreFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCaseUtil.java From chronus with Apache License 2.0 | 6 votes |
public static String object2JsonString(Object object,Class clazz,String... ignoreField){ Field[] fields = clazz.getDeclaredFields(); String[] fieldName = new String[fields.length-ignoreField.length]; int i = 0; for(Field field:fields) { List<String> ignoreFields = Arrays.asList(ignoreField); if(!ignoreFields.contains(field.getName())) { fieldName[i++] = field.getName(); } } SimplePropertyPreFilter filter = new SimplePropertyPreFilter(clazz, fieldName); return JSON.toJSONString(object,filter, SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullListAsEmpty); }
Example #2
Source File: JsonUtils.java From android-Stupid-Adapter with Apache License 2.0 | 5 votes |
/** * 将给定的目标对象根据指定的过滤参数转换成 JSON 格式的字符串。 * * @param target * @param clazz * @param properties * @return */ public static String toJSONString(Object target, Class<?> clazz, String... properties) { if (target == null) return EMPTY_JSON; SimplePropertyPreFilter filter = new SimplePropertyPreFilter(clazz, properties); return JSON.toJSONString(target, filter); }
Example #3
Source File: JsonUtils.java From spring-boot-vue-admin with Apache License 2.0 | 4 votes |
private static <T> T done( final Object target, final Class<T> clz, final SimplePropertyPreFilter filter) { final String jsonString = JSON.toJSONString(target, filter); return JSON.parseObject(jsonString, clz); }
Example #4
Source File: JsonUtils.java From spring-boot-vue-admin with Apache License 2.0 | 3 votes |
/** * 去除某些字段 * * @param target 目标对象 * @param fields 字段 * @return 去除字段后的对象 */ public static <T> T deleteFields( final Object target, final Class<T> clz, final String... fields) { final SimplePropertyPreFilter filter = new SimplePropertyPreFilter(); filter.getExcludes().addAll(Arrays.asList(fields)); return done(target, clz, filter); }
Example #5
Source File: JsonUtils.java From spring-boot-vue-admin with Apache License 2.0 | 2 votes |
/** * 保留某些字段 * * @param target 目标对象 * @param fields 字段 * @return 保留字段后的对象 */ public static <T> T keepFields(final Object target, final Class<T> clz, final String... fields) { final SimplePropertyPreFilter filter = new SimplePropertyPreFilter(); filter.getIncludes().addAll(Arrays.asList(fields)); return done(target, clz, filter); }