MichaelB
MichaelB

Reputation: 1132

ISODate fails to parse from Spring Boot JPA repo

I have a SpringBoot JPA Repository that finds a bunch of "things" in a MongoDB instance that has a field called "lastModified" which is an ISODate() as per the below.

{ "name": "a", "lastModified", "ISODate(2018-04-19T19:10:39.356574)" }

When I use a repository function like:

public List<Thing> findByName(String name);

I get a

org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value 'ISODate(2018-04-18T18:38:42.635027)'; nested exception is java.lang.IllegalArgumentException

I have tried

Am I missing something about how Mongo does this conversion? I would expect it turns that ISODate into a simple string and passes it into the setLastModified(String name) function but I guess that's not the case?

Upvotes: 0

Views: 489

Answers (1)

MichaelB
MichaelB

Reputation: 1132

Turns out it was just because the date was inserted as a string of "ISODate(2018-04-19T19:10:39.356574)" instead as a Date which would be like ISODate("2018-04-17T19:43:00Z")

Once I went and found and fixed the source of this data, it started working properly.

Upvotes: 1

Related Questions