json - json4s serializes a case class Test("test") to "{}" on Android -
i'm serializing case class graph json in android scala app (using "com.hanhuy.sbt" % "android-sdk-plugin" % "1.3.5"
).
i'm using "org.json4s" %% "json4s-native" % "3.2.10"
, , fails simple case class looks this:
package test case class test(text: string)
the code serialize looks this:
import org.json4s._ import org.json4s.native.serialization import org.json4s.native.serialization.{read, write} // ... implicit val formats = serialization.formats(notypehints) val test = test("test") val serialized = write(test) info(s"serialized '$serialized'")
the output is:
serialized '{}'
i suspect proguard problem , proguard settings in build.sbt
this:
proguardscala in android := true proguardoptions in android ++= seq( "-dontobfuscate", "-dontoptimize", "-keepattributes signature", "-dontwarn scala.collection.**", // required scala 2.11.3 "-dontwarn scala.collection.mutable.**", // required scala 2.11.0 "-ignorewarnings", "-keep class scala.dynamic", "-keep class test.**" )
i tried json4s-jackson
made no difference.
the proguard log looks this:
warning: com.thoughtworks.paranamer.annotationparanamer$jsr330helper: can't find referenced class javax.inject.named warning: com.thoughtworks.paranamer.annotationparanamer$jsr330helper: can't find referenced class javax.inject.named warning: org.joda.convert.jdkstringconverter$9: can't find referenced class javax.xml.bind.datatypeconverter warning: org.joda.convert.jdkstringconverter$9: can't find referenced class javax.xml.bind.datatypeconverter warning: org.joda.convert.jdkstringconverter$9: can't find referenced class javax.xml.bind.datatypeconverter note: com.google.android.gms.internal.av calls '(com.google.ads.mediation.mediationadapter)class.forname(variable).newinstance()' note: com.google.android.gms.maps.internal.q: can't find dynamically referenced class com.google.android.gms.maps.internal.creatorimpl note: org.joda.time.datetimezone calls '(org.joda.time.tz.provider)class.forname(variable).newinstance()' note: org.joda.time.datetimezone calls '(org.joda.time.tz.nameprovider)class.forname(variable).newinstance()' note: there 1 unresolved dynamic references classes or interfaces. should check if need specify additional programme jars. (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass) note: there 3 class casts of dynamically created class instances. might consider explicitly keeping mentioned classes and/or implementations (using '-keep'). (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclasscast) warning: there 5 unresolved references classes or interfaces. may need add together missing library jars or update versions. if code works fine without missing classes, can suppress warnings '-dontwarn' options. (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass) note: you're ignoring warnings!
any ideas?
you can create jsonobject string using constructor:
jsonobject json = new jsonobject(mystring);
and convert jsonobject string, utilize tostring() method:
string mystring = json.tostring();
additionally, if trying specific string value jsonobject, can this:
if (json.has("content")) { string content = json.getstring("content"); //do content string }
finally, if aren't comfortable using jsonobject, recommend using tools provided droidquery help parse, such as:
object[] array = $.toarray(myjsonarray);
and
map<string, ?> map = $.map(myjsonobject);
android json proguard json4s
No comments:
Post a Comment