1

I have this exception when converting a Long to a Joda DateTime.

org.springframework.core.convert.ConverterNotFoundException:
    No converter found capable of converting from type java.lang.Long
    to type org.joda.time.DateTime

I'm using

        artifactId>spring-core</artifactId>
        <version>4.0.3.RELEASE</version>

        <artifactId>spring-integration-core</artifactId>
        <version>4.0.3.RELEASE</version>

        <artifactId>spring-integration-mongodb</artifactId>
        <version>4.0.3.RELEASE</version>

        <artifactId>spring-integration-mail</artifactId>
        <version>4.0.3.RELEASE</version>


        <artifactId>spring-messaging</artifactId>
        <version>4.0.3.RELEASE</version>

        <artifactId>spring-integration-xml</artifactId>
        <version>4.0.3.RELEASE</version>

        <artifactId>json-path</artifactId>
        <version>0.9.1</version>

        <artifactId>spring-data-commons-core</artifactId>
        <version>1.4.0.RELEASE</version>

        <artifactId>spring-data-commons</artifactId>
        <version>1.8.1.RELEASE</version>

Does anyone know what else I need to convert a Long to a DateTime?

Thanks

Mike

3
  • Maybe you can also post the piece of code that causes this exception!
    – isnot2bad
    Jul 25, 2014 at 14:28
  • The code is actually inside spring classes. I occurs when deserialising an entity containing a long representation of a DataTime. i.e. GenericConversionService.convert(GenericConversionService.java:177)
    – BanditPig
    Jul 25, 2014 at 14:54
  • Adding Jodatime tag will attract Jon Skeet's attention ;)
    – VladL
    Jul 25, 2014 at 15:27

1 Answer 1

1

Try the DateTime(long instant) route. If you need to format, try converting the long to a String and then use the DateTimeFormatter:

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

    long abc;  //assign some value to this long
    String s = String.valueOf(abc);  //convert long to string
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.S");  ///modify this according to your needs    
    DateTime dt = formatter.parseDateTime(date);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.