我有一個要求,我已經創建了一個自定義註釋@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