3

I'm using Joda objects (DateTime and DateTimeZone) in a document and whenever I access it via the REST interface I get entries with fields like this

lastAggregationDate: { content: "2016-07-12T17:58:43.643Z" }

instead of

lastAggregationDate: "2016-07-12T17:58:43.643Z"

I have the Joda Jackson dependencies declared and I see the de/serializers for these types so I'm puzzled as to what's at work here.

I've duplicated this behavior in a slightly modified Spring sample project but using Java's native date types rather than Joda's. I've added a date of birth property to the Person object and modified the shouldRetrieveEntity test to look for $.dateOfBirth.content. I've confirmed the serializer is being used and it seems like the LocalDate object is being treated as a resource rather than as a simple property.

roborative
  • 164
  • 1
  • 11
  • See also http://stackoverflow.com/q/39170405/466738 for the same problem – Adam Michalik Sep 01 '16 at 07:20
  • Thanks, Adam. Marc does a great job of documenting the issue and his post is helpful in that he calls out the upgrade to 1.4.0 as causing the issue. I suspected the same and will add a branch using the pre-1.4.0 dependencies to my sample to confirm. – roborative Sep 01 '16 at 16:17
  • I've added a [branch](https://github.com/robmoore/gs-accessing-mongodb-data-rest/tree/spring-1.3.7) with the modified test code to demonstrate that 'content' wasn't present prior to 1.4.0. – roborative Sep 02 '16 at 16:58
  • I've created a [ticket for this issue](https://jira.spring.io/browse/DATAREST-888). Please vote for it if it's impacting you. – roborative Sep 10 '16 at 14:38

2 Answers2

2

This is fixed in Spring Data Hopper-SR4: https://jira.spring.io/browse/DATAMONGO-1498

Sergey Shcherbakov
  • 4,534
  • 4
  • 40
  • 65
1

The issue results from Spring Boot not setting up MongoMappingContext correctly. A ticket has been created for Spring Boot and the fix is anticipated for the 1.4.1 release (credit for this answer goes to Oyku Gencay and Oliver Gierke). For more detail, see the ticket or the pull request.

roborative
  • 164
  • 1
  • 11
  • I've just updated my dependencies to Sprint Boot 1.4.1. The tests added by the pull request checks the results with a java.time.LocalDateTime. The issue described with joda time objects remains. – Marc Tarin Sep 26 '16 at 15:28
  • Forget about my previous comment: upgrading to Spring Boot 1.4.1 *does* solve the issue described in this post, though if you annotate the main application class with @EnableMongoAudit, it breaks the serialization again. – Marc Tarin Oct 04 '16 at 14:02
  • I've seen the same thing with my project (as opposed to the sample mentioned above). I ended up using `@JsonUnwrapped` in the interim as was mentioned in the Spring ticket. – roborative Oct 06 '16 at 16:19
  • Spring Boot 1.4.2 definitely solved the issue, whether the application is annotated with @EnableMongoAudit or not. – Marc Tarin Jan 25 '17 at 10:03