我有一个要求,我已经创建了一个自定义注释@MaskSensitiveData。我注释敏感领域。像自定义Jackson ObjectMapper读取自定义注释和掩码字段注释
class MyBean {
String userName;
@MaskSensitiveData
String cardNumber;
String abc;
String xyz;
}
ObjectMapper mapper = new ObjectMapper();
String json = null;
AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary);
mapper.setAnnotationIntrospector(pair);
try {
json = mapper.writeValueAsString(obj);
/*
* if(json != null) { json = getLoggableString(json); }
*/
} catch (Exception e) {
return "Unable to convert to Json object:" + obj.toString() + " Message: " + e.getMessage();
}
我使用的是Jackson ObjectMapper将objct转换为Json。 我需要自定义对象映射器来屏蔽cardNumber字段以返回json。 请建议一个更好的方法。
这是罚款,只要所有的属性都是String类型。如果您将abc作为具有自己属性的更复杂的类型,那么您将如何将它们打印为json?我也有这个问题,不知道解决方案呢... – dune76
https://stackoverflow.com/q/46021769/5667890这是我目前的问题,我仍然没有线索 – dune76