-
Notifications
You must be signed in to change notification settings - Fork 683
Spring Data Commons does not support org.joda.DateTime in auditing [DATACMNS-1478] #1910
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
Comments
Oliver Drotbohm commented The support for Joda's Jens Schauder can probably comment on the details |
Jens Schauder commented Conceptually: Use Don't use Leaving the puristic arguments aside: We do support various date-time related data types which aren't really fit for the job. We could either remove support for those which will cause tons of issues and questions although it might make the world a better place. Or we just (re(?))add I actually think we should support Joda |
jvanheesch commented Any updates on this? |
abinet commented jvanheesch you can workaround by configuring a MappingContext: @Configuration
public class MongoDbConfig {
@Bean
public MongoMappingContext mongoMappingContext() {
MongoMappingContext context = new MongoMappingContext();
context.setSimpleTypeHolder(new SimpleTypeHolder(new HashSet<>(Arrays.asList(
DateTime.class,
LocalDateTime.class
)), MongoSimpleTypes.HOLDER));
return context;
}
} |
jvanheesch commented Thank you abinet for adding your workaround - it'll definitely help others with the same problem! @Configuration
public class MyRepositoryRestMvcConfiguration extends RepositoryRestMvcConfiguration {
public MyRepositoryRestMvcConfiguration(
ApplicationContext context,
@Qualifier("mvcConversionService") ObjectFactory < ConversionService > conversionService
) {
super(context, conversionService);
}
@Bean
public HttpHeadersPreparer httpHeadersPreparer() {
return new HttpHeadersPreparer(auditableBeanWrapperFactory()) {
@Override
public HttpHeaders prepareHeaders(PersistentEntity < ? , ? > entity, Object value) {
Assert.notNull(entity, "PersistentEntity must not be null!");
Assert.notNull(value, "Entity value must not be null!");
// Add ETag
HttpHeaders headers = ETag.from(entity, value).addTo(new HttpHeaders());
// Don't add Last-Modified, as this does not work with joda time!
// getLastModifiedInMilliseconds(value).ifPresent(it -> headers.setLastModified(it));
return headers;
}
};
}
} |
Meanwhile, we've deprecated Joda support and we're planning to remove support for Joda time entirely with Spring Data 3.0 (#2276). Therefore, we don't intend to address this issue anymore. |
abinet opened DATACMNS-1478 and commented
Hi all,
it seems that support of
org.joda.DateTime
is broken in latest Spring Data Commons. When I create a mongo entity with:I get following error:
It happens probably because
org.springframework.data.convert.JodaTimeConverters
does not have the converter fromorg.joda.time.DateTime
<=>Instant
but onlyorg.joda.time.LocalDateTime
<=>Instant
althoughorg.joda.time.DateTime
still inorg.springframework.data.auditing.AnnotationAuditingMetadata#SUPPORTED_DATE_TYPES
.Currently I can not find the way how to put my custom converter into
conversionService
to workaround thisorg.springframework.data.auditing.DefaultAuditableBeanWrapperFactory.DateConvertingAuditableBeanWrapper#DateConvertingAuditableBeanWrapper
Best regards
Andriy Binetsky
Affects: 2.1.4 (Lovelace SR4)
1 votes, 4 watchers
The text was updated successfully, but these errors were encountered: