Tim
12 years ago
I have a simple Scala class:
import com.google.gson.annotations.SerializedName
val testJson = "{\"myTest\": \"my-test\"}"
In reality, my JSON looks like this:
val testJsonWithUnderscore = "{\"my_test\": \"my-test\"}"
JSON string. So I included *@SerializedName("my_test")* but it does not
work. The var *myTest* is *null*.
The *@SerializedName("my_test")* does not work like expected. What is wrong
here?
import com.google.gson.annotations.SerializedName
extends Serializable { ... }
And I have this code:val testJson = "{\"myTest\": \"my-test\"}"
val myTest = gson.fromJson(testJson, classOf[MyTest])
This works fine! The content of the variable of *myTest* is *my-test*.In reality, my JSON looks like this:
val testJsonWithUnderscore = "{\"my_test\": \"my-test\"}"
val myTest = gson.fromJson(testJsonWithUnderscore, classOf[MyTest])
So, the variable name *myTest* does not match with the *my_test* of theJSON string. So I included *@SerializedName("my_test")* but it does not
work. The var *myTest* is *null*.
The *@SerializedName("my_test")* does not work like expected. What is wrong
here?
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.