Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to replace non String Json Properties #478

Closed
jhordies opened this issue Apr 9, 2019 · 4 comments · Fixed by #530
Closed

Add a way to replace non String Json Properties #478

jhordies opened this issue Apr 9, 2019 · 4 comments · Fixed by #530

Comments

@jhordies
Copy link

jhordies commented Apr 9, 2019

It would be convenient to be able to replace numeric values in json the same way string values are replaced

Detailed Description

public static BodyFilter replaceJsonStringProperty(final Set properties, final String replacement)
could become
public static BodyFilter replaceJsonProperties(final Set properties, final String stringReplacement, float numericReplacement)

Context

I need to obfuscate numerci data in my json request and responses because they are sensitive data i don't want to log.
I believe I wouldn't be the only one with this need as it is foreseen for strings but not numeric values

BTW: why not allowing inheritance with final classes and why the package private classes ?
Thanks for this library that could really fulfill our needs if this feature request was implemented.

@whiskeysierra
Copy link
Collaborator

I need to obfuscate numerci data in my json request and responses because they are sensitive data i don't want to log.

Makes sense, totally agree that this should be supported.

I believe I wouldn't be the only one with this need as it is foreseen for strings but not numeric values

You're atleast the first one to ask for numbers. But yes, it's generic enough to be solved within logbook.

could become
public static BodyFilter replaceJsonProperties(final Set properties, final String stringReplacement, float numericReplacement)

I'm rather looking into having replacePrimitiveJsonProperties(Set<String> properties, String rawJsonReplacement) (as a private implementation). That way we could allow strings, numbers, booleans and null(?) as typed replacements.

BTW: why not allowing inheritance with final classes and why the package private classes ?

In a nutshell: https://en.wikipedia.org/wiki/Composition_over_inheritance

Designing APIs is hard enough as it stands. Allowing for implementation inheritance makes so much harder. There is not a single problem, in my experience, that can be solved with class inheritance exclusively. Quite the contrary, the best solutions and cleanest class designs that I've seen avoid it like the plague.

I'm not whether I can jump in and prepare something here, but I see two options that both rely on you helping yourself 😜

  1. Open a pull request, introduce an additional method to JsonBodyFilters similar to this https://github.com/zalando/logbook/blob/master/logbook-json/src/main/java/org/zalando/logbook/json/JsonBodyFilters.java#L46
  • make it work for any primitive
  • add good tests (we have examples for the existing version, you can take those as a blueprint)
  1. Implement a custom body filter in your own project just for you. Again, just take the existing version as a blue print and implement your own version. The version for string-properties is 5 lines of code. Adding support for numbers should only increase the size of the regex, tbh.

@whiskeysierra
Copy link
Collaborator

Thanks for this library that could really fulfill our needs

🙇‍♂️

@skjolber
Copy link
Contributor

Jackson-based filter which supports all data types based on property name: #512

@whiskeysierra
Copy link
Collaborator

@jhordies See #530

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants