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

Need something better than toString for converting args #22

Closed
massfords opened this issue Dec 25, 2015 · 4 comments
Closed

Need something better than toString for converting args #22

massfords opened this issue Dec 25, 2015 · 4 comments
Labels

Comments

@massfords
Copy link

Very nice library!

The conversion of the method args to a List is based on the arg's toString() implementation. It would be nice to support a pluggable conversion from object to a String or even support producing multiple Field's from a single argument.

Consider the following case:

public MyDTO create(MyDTO arg) { ... }

In this case, I'd like to record a couple of different fields from the MyDTO arg as opposed to relying solely on its toString() implementation.

I'm thinking I can add the behavior I want by writing my own version of AnnotationTransformer and then using it in an AuditOutputStream but it would be nice if this had a declarative / annotation driven solution. For spring users in particular, it would be great to have the option of an annotation that produced a List using different names and SpEL (spring expression language). For example, I could annotate the above method with an array of annotations each one having a name and SpEL that would extract the field I want to include in the AuditEvent.

@janithb
Copy link
Contributor

janithb commented Dec 26, 2015

Hi @massfords ,

We already Identified this issue and currently in progress of developing the solution. We thought of using pluggable serializer to extract object to relevant audit record based on annotations in the object fields (ex: MyDTO). I have developed below couple of serializes similar to old toString implementation. Please refer below implementations.

https://github.com/audit4j/audit4j-core/blob/master/src/main/java/org/audit4j/core/ObjectToFieldsSerializer.java

https://github.com/audit4j/audit4j-core/blob/master/src/main/java/org/audit4j/core/ObjectToStringSerializer.java

Using this method, users are able to plug their own serializer implementation based on the requirement (Ex: JSONable, XML). then you don't need to implement a custom a annotation transformer

What do you think.

@massfords
Copy link
Author

A pluggable serializer seems like the right approach. I took a quick look at the source. I don't see a way to configure the serializer yet but I'm guessing this is still a work in progress.

@janithb
Copy link
Contributor

janithb commented Feb 22, 2016

This issue is resolved.

Fixes are available in Audit4j 2.4.1-RC1 release

@massfords Please test and verify.

@janithb
Copy link
Contributor

janithb commented Mar 2, 2016

This issue is fixed in 2.4.1

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

No branches or pull requests

2 participants