Skip to content

Allow customizing AuditableBeanWrapperFactory #2040

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

Closed
alienisty opened this issue Jul 13, 2021 · 2 comments
Closed

Allow customizing AuditableBeanWrapperFactory #2040

alienisty opened this issue Jul 13, 2021 · 2 comments
Assignees
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@alienisty
Copy link

alienisty commented Jul 13, 2021

We use OffsetDateTime for our auditing data, but a property of such type annotated with @LastModifiedDate fails to convert it to instant because the converters in Jsr310Converters do not provide a converter from OffsetDateTime to Date.
The other problem is that the annotation is only supported on entity properties or their getters and is allowed but with no effect on methods that are not properties getters.
For example, we'd like to add the Last-Modified-Date header as a trait, using an interface, for example:

public interface LastModifiedAware {
  @LastModifiedDate
  public TemporalAccessor getLastModifiedDate();
}

public class MyEntity implements LastModifiedAware {
  ...
  private OffsetDateTime lastModified;
  ...
 
  public OffsetDateTime getLastModifiedDate() {
    return lastModified;
  }
}

The above does not work out of the box so we customise the AuditableBeanWrapperFactory by delegating to MappingAuditableBeanWrapperFactory for the "standard" case and to a custom implementation to support our desired mechanism.

Recently though, as reported in #1981, RepositoryRestMvcConfiguration can no longer be subclassed, so we would like to either restore the previous support, or add the ability to obtain the desired behaviour.

@odrotbohm
Copy link
Member

We can certainly introduce a callback on RepositoryRestConfigurer but be advised that using time-zoned dates in your domain model is begging for trouble unless the backing data store has explicit support for that. I am not aware that any of the backends of the Spring Data modules actually have that. That's the primary reason we do not natively support those types in any of our mapping subsystems in the first place.

@odrotbohm odrotbohm removed the status: waiting-for-triage An issue we've not yet triaged label Jul 14, 2021
@odrotbohm odrotbohm self-assigned this Jul 14, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 14, 2021
@odrotbohm odrotbohm added this to the 3.6 M1 (2021.1.0) milestone Jul 14, 2021
@odrotbohm odrotbohm changed the title @LastModifiedDate does not support OffsetDateTime properties Allow customizing AuditableBeanWrapperFactory Jul 14, 2021
@alienisty
Copy link
Author

Using 2021.1.0-SNAPSHOT I tried using the new customization mechanism and it all works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants