enhancement request - ability to customize field values during serialization (java -> json)

530 views
Skip to first unread message

Doug Lethin

unread,
Oct 27, 2012, 10:44:49 PM10/27/12
to googl...@googlegroups.com
Forgive me if this was discussed before.  I did a quick search on mask and password but came up empty handed.  

I'm using Gson to log some of my objects to a log file.  However, some fields are sensitive and I would like to mask them.  I understand there is support to provide custom a custom strategy to determine if a field should be included or not, as well as possibly a way to customize what the field name should be.  However, there does not seem to be a way to customize how you want mask the data.  Take for example a credit card number or bank account.  Logging the full # is bad.  However, I do want to log something, not just skip the field.  Perhaps just logging the last 4 digits of the #, ala XXXXXXXXXXXX1234

As a workaround, I could mark the credit card field @Transient and define a new field which contains the masked value. and log that instead.  This seems a bit cumbersome.  But just as you can customize a field-inclusion strategy, it seems fitting to provide a simple mechanism to provide some form of field-value-conversion strategy.  The default would just be the field value itself without any manipulation.

Then I could simply annotate my fields with some indicator as to the mask algorithm.  My custom field-value-conversion strategy would look for my custom annotation and apply the referenced algorithm.


Not sure if this ever made its way into a formal request to the gson team to add this support. As I mentioned earlier, I didn't find anything..

Thanks,

Doug

Reply all
Reply to author
Forward
0 new messages