0

I have a problem with joda-time and its integration to my Android app.

I want to deserialize JSON which contains a DateTime object which is represented with a string:

{
     "userId": 333,
     "username": "myuserid",
     "timestamp": "2014-11-19T17:02:11.454Z"
}

But unfortunatelly I receive a NoClassDefFoundError.

java.lang.NoClassDefFoundError: org/joda/convert/ToString...     
Caused by: java.lang.ClassNotFoundException: org.joda.convert.ToSt

I tried to add joda-converter and to add joda-time dependency with the same version as server has. But inspite of this I constantly receive the exception. My current joda-time dependecies are:

compile 'org.joda:joda-convert:1.8.1'
compile 'joda-time:joda-time:2.1'

I also tried to user joda-time-android but it also was not successful.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user2957954
  • 1,221
  • 2
  • 18
  • 39

1 Answers1

1

Looking into the org.joda.convert I found out, that org.joda.convert.ToString is an interface. You cannot use it to convert.
Assuming that you successfully parsed JSON String and your object's definition is:

public class json {
    private Long userId;
    private String username;
    private String timestamp;
}

And here is the question what would you like to do, because you haven't precised exactly.
If you would like to convert String timespamp to DateTime object from joda-time library, follow this link. It provides solution to parse it, as the date you provided is a standard ISO-8601 date describing format.

However importing whole library just to parse a String to Date is an inefficient solution. joda-time suffers from slow initialisation and the performace matters on Android. Follow this link to convert String to Java's Date object without importing a library, which has 4755 methods.

Community
  • 1
  • 1
R. Zagórski
  • 20,020
  • 5
  • 65
  • 90