/**
* emoji过滤器
* @param
*/
class EmojiFilter<T>{
/**
* 传入一个bean,将其下的所有java.lang.String类型的列中含有的emoji全部去除
* @param obj
* @return
*/
private T filter(T obj){
Field[] fields = obj.getClass().getDeclaredFields();
for(Field field : fields){
field.setAccessible(true);
try {
Object value = field.get(obj);
if(value instanceof java.lang.String){
if(value != null){
value = filterEmoji(value.toString());
field.set(obj,value);
}
}
} catch (IllegalAccessException e) {
try {
field.set(obj,field.get(e));
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
}
}
return obj;
}
/**
* 将emoji表情替换成*
* @param source
* @return 过滤后的字符串
*/
private String filterEmoji(String source) {
if(StringUtil.isNotBlank(source)){
return source.replaceAll("[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]", "*");
}else{
return source;
}
}
}