0

I need convert ParseObject to Json and in other time convert the Json back in ParseObject,but when I use Gson for example, don't work.

I try any forms,but no have success,my class is this:

class MyClass{

private var  obj:ParseObject?=null

....gets/sets using this object


}

i need convert the obj.

Thankss ;)

Manuel
  • 14,274
  • 6
  • 57
  • 130
Paulo César
  • 806
  • 6
  • 8

1 Answers1

0

try

  fun fromObject(data: MyObject?): String? {
    data ?: return null
    return Gson().toJson(data, object : TypeToken<MyObject>() {}.type)
  }

  fun toObject(string: String?): MyObject? {
    string ?: return null
    return Gson().fromJson<MyObject>(string, object : TypeToken<MyObject>() {}.type)
  }
TootsieRockNRoll
  • 3,218
  • 2
  • 25
  • 50
  • i try but receive back error ,(java.lang.IllegalArgumentException: No ParseClassName annotation provided on class com.parse.ParseObject,Method threw 'java.lang.RuntimeException' exception.,Failed to invoke protected com.parse.ParseObject() with no args), i try using in MyObject -->ParseObject,Thanks for your help. – Paulo César Apr 18 '20 at 21:24
  • post your com.parse.ParseObject class – TootsieRockNRoll Apr 18 '20 at 21:40
  • i use obj: ParseObject native, not have class modifying ,i need transfer this object for other fragment,but the Parcelable broken when i get in onCreate, now i trying transfer string,for solved my problem – Paulo César Apr 18 '20 at 21:46