@Test public void testToString() { TestData testData = new TestData(); testData.setName("123"); testData.setPhone("1234567"); testData.setAccount("test"); testData.setHash("hash"); testData.setTest("123456"); String mask = DataMask.toString(testData); System.out.println(mask); testData.setName("**3"); testData.setPhone("12***67"); testData.setAccount("t***"); testData.setTest("1**456"); testData.setHash(new HashMask().mask("hash", null)); assertThat(mask).isEqualTo(testData.toString()); }
public static String toString(Object object) { if (object == null) { return null; } try { String json = toJSONString(object); Object cloneObj = JSON.parseObject(json, object.getClass()); return cloneObj.toString(); } catch (Exception e) { return object.toString(); } }
DataMask { public static String toString(Object object) { if (object == null) { return null; } try { String json = toJSONString(object); Object cloneObj = JSON.parseObject(json, object.getClass()); return cloneObj.toString(); } catch (Exception e) { return object.toString(); } } }
DataMask { public static String toString(Object object) { if (object == null) { return null; } try { String json = toJSONString(object); Object cloneObj = JSON.parseObject(json, object.getClass()); return cloneObj.toString(); } catch (Exception e) { return object.toString(); } }  }
DataMask { public static String toString(Object object) { if (object == null) { return null; } try { String json = toJSONString(object); Object cloneObj = JSON.parseObject(json, object.getClass()); return cloneObj.toString(); } catch (Exception e) { return object.toString(); } }  static void setHashSalt(String salt); static String mask(String source); static String mask(String source, SensitiveType type); static String mask(String source,MaskStrategy strategy,int...param); static String toJSONString(Object object); static String toString(Object object); }
DataMask { public static String toString(Object object) { if (object == null) { return null; } try { String json = toJSONString(object); Object cloneObj = JSON.parseObject(json, object.getClass()); return cloneObj.toString(); } catch (Exception e) { return object.toString(); } }  static void setHashSalt(String salt); static String mask(String source); static String mask(String source, SensitiveType type); static String mask(String source,MaskStrategy strategy,int...param); static String toJSONString(Object object); static String toString(Object object);  }