Reputation: 12915
Is there the way to cast a string value within json to an int-, long- or double-member using GSON?
What I mean, I have a json string, something like this:
{'timestamp':'1243274283728', 'distanse':'122.1'}
And I want to map this json string to object of following class:
public class TestClass
{
public long timestamp;
public double distance;
}
Thank you in advance
Upvotes: 1
Views: 1020
Reputation: 4706
Doesn't this work?
TestClass obj = new Gson().fromJson(
"{'timestamp':'1243274283728', 'distance':'122.1'}",
TestClass.class);
Upvotes: 2