GSON: Illegal Argument exception when converting a json string to a Java object -
i'm working youtube api. can convert java object json string. when try reverse (json string java object) throws exception: can not set com.google.api.services.youtube.model.commentthreadsnippet field com.google.api.services.youtube.model.commentthread.snippet java.util.linkedhashmap
. why error , how fix it?
this works:
commentthread commentthread = getitsomehow() gson gson = new gson(); string jsonstr = gson.tojson( commentthread );
reverse throws exception:
commentthread fromjson = gson.fromjson( jsonstr, commentthread.class );
here commentthread class:
@suppresswarnings("javadoc") public final class commentthread extends com.google.api.client.json.genericjson { /** * etag of resource. * value may {@code null}. */ @com.google.api.client.util.key private java.lang.string etag; /** * id youtube uses uniquely identify comment thread. * value may {@code null}. */ @com.google.api.client.util.key private java.lang.string id; /** * identifies kind of resource is. value: fixed string "youtube#commentthread". * value may {@code null}. */ @com.google.api.client.util.key private java.lang.string kind; /** * replies object contains limited number of replies (if any) top level comment found * in snippet. * value may {@code null}. */ @com.google.api.client.util.key private commentthreadreplies replies; /** * snippet object contains basic details comment thread , top level * comment. * value may {@code null}. */ @com.google.api.client.util.key private commentthreadsnippet snippet; /** * etag of resource. * @return value or {@code null} none */ public java.lang.string getetag() { return etag; } /** * etag of resource. * @param etag etag or {@code null} none */ public commentthread setetag(java.lang.string etag) { this.etag = etag; return this; } /** * id youtube uses uniquely identify comment thread. * @return value or {@code null} none */ public java.lang.string getid() { return id; } /** * id youtube uses uniquely identify comment thread. * @param id id or {@code null} none */ public commentthread setid(java.lang.string id) { this.id = id; return this; } /** * identifies kind of resource is. value: fixed string "youtube#commentthread". * @return value or {@code null} none */ public java.lang.string getkind() { return kind; } /** * identifies kind of resource is. value: fixed string "youtube#commentthread". * @param kind kind or {@code null} none */ public commentthread setkind(java.lang.string kind) { this.kind = kind; return this; } /** * replies object contains limited number of replies (if any) top level comment found * in snippet. * @return value or {@code null} none */ public commentthreadreplies getreplies() { return replies; } /** * replies object contains limited number of replies (if any) top level comment found * in snippet. * @param replies replies or {@code null} none */ public commentthread setreplies(commentthreadreplies replies) { this.replies = replies; return this; } /** * snippet object contains basic details comment thread , top level * comment. * @return value or {@code null} none */ public commentthreadsnippet getsnippet() { return snippet; } /** * snippet object contains basic details comment thread , top level * comment. * @param snippet snippet or {@code null} none */ public commentthread setsnippet(commentthreadsnippet snippet) { this.snippet = snippet; return this; } @override public commentthread set(string fieldname, object value) { return (commentthread) super.set(fieldname, value); } @override public commentthread clone() { return (commentthread) super.clone(); } }
below details of exception.
throwable: can not set com.google.api.services.youtube.model.commentthreadsnippet field com.google.api.services.youtube.model.commentthread.snippet java.util.linkedhashmap java.lang.illegalargumentexception: can not set com.google.api.services.youtube.model.commentthreadsnippet field com.google.api.services.youtube.model.commentthread.snippet java.util.linkedhashmap @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:167) @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:171) @ sun.reflect.unsafeobjectfieldaccessorimpl.set(unsafeobjectfieldaccessorimpl.java:81) @ java.lang.reflect.field.set(field.java:764) @ com.google.api.client.util.fieldinfo.setfieldvalue(fieldinfo.java:245) @ com.google.api.client.util.fieldinfo.setvalue(fieldinfo.java:206) @ com.google.api.client.util.genericdata.put(genericdata.java:103) @ com.google.api.client.util.genericdata.put(genericdata.java:47) @ com.google.gson.internal.bind.maptypeadapterfactory$adapter.read(maptypeadapterfactory.java:189) @ com.google.gson.internal.bind.maptypeadapterfactory$adapter.read(maptypeadapterfactory.java:146) @ com.google.gson.gson.fromjson(gson.java:755) @ com.google.gson.gson.fromjson(gson.java:721) @ com.google.gson.gson.fromjson(gson.java:670) @ com.google.gson.gson.fromjson(gson.java:642) @ sam.ut.commentthreads.handlecommentsthreads(commentthreads.java:157) @ sam.ut.commentthreads.downloadcommentsforthisvideo(commentthreads.java:84) @ sam.ut.commentthreads.main(commentthreads.java:66)
edit: , here json:
{ "etag": "\"0fu6li6vpldrmlqu3wwncowdaus/f7byskj8z3darwhusu5zinnzkqw\"", "id": "z12wxpxozzy1tdxop04cjd1rjzq4cp2jgfw", "kind": "youtube#commentthread", "snippet": { "canreply": true, "ispublic": true, "toplevelcomment": { "etag": "\"0fu6li6vpldrmlqu3wwncowdaus/pzvv_vfrn7czovsiilpnvseiwe0\"", "id": "z12wxpxozzy1tdxop04cjd1rjzq4cp2jgfw", "kind": "youtube#comment", "snippet": { "authorchannelid": { "value": "ucojtszsvhfakfqprwn3etlq" }, "authorchannelurl": "http://www.youtube.com/channel/ucojtszsvhfakfqprwn3etlq", "authordisplayname": "spruce moose arts", "authorgoogleplusprofileurl": "https://plus.google.com/102869292172467105853", "authorprofileimageurl": "https://lh6.googleusercontent.com/-ejgw19enrkq/aaaaaaaaaai/aaaaaaaaayg/khd3hglrox4/photo.jpg?sz=50", "canrate": true, "likecount": 0, "publishedat": "2016-06-13t22:49:52.000z", "textdisplay": "the man behind camera recorded this, must shaky, \ncondsidering amount of warp stabilization on video :p also, \nthink matter of personal taste. think car \npol filter looked better.", "updatedat": "2016-06-13t22:49:52.000z", "videoid": "yczkcnps45s", "viewerrating": "none" } }, "totalreplycount": 0, "videoid": "yczkcnps45s" } }
Comments
Post a Comment