java


How to deserialize a json data using GSON?


[{"contacts":
[
{
"name": "Ramesh Sippi",
"email": "ramesh.sippi#gmail.com",
"phone": 9972366543,
"officePhone": 80012345676,
"latitude": 18.5204,
"longitude": 73.8567
}
]
}]
I tried to deserialize above JSON but it shows :
java.lang.IllegalStateException: Not a JSON Object
Deserializer class is:
public class Deserializer implements JsonDeserializer<List<ContactDetails>> {
#Override
public List<ContactDetails> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String CONTACTS = "contacts";
return new Gson().fromJson(json.getAsJsonArray().getAsJsonObject().getAsJsonArray(CONTACTS),typeOfT);
}}
Please help me out.Any resource or tutorial which helped you in deserialization.
json.getAsJsonArray().getAsJsonObject() is the same as json.getAsJsonObject(), and that is the cause of your exception.
You likely meant json.getAsJsonArray().get(0).getAsJsonObject().
It looks like you have your json inside [], which would indicate an array. Try:
{
"contacts":
[
{
"name": "Ramesh Sippi",
"email": "ramesh.sippi#gmail.com",
"phone": 9972366543,
"officePhone": 80012345676,
"latitude": 18.5204,
"longitude": 73.8567
}
]
}

Related Links

Modifying a plain ANLTR file in background
Printing StringBuffer JOptionPane
Java Netbeans Derby how can I check if a database is encrypted?
Gson library error
When do I use List and when do I use ArrayList, also LinkedList in Java? [duplicate]
RESTEasy JSON Exception Response: Send list of objects
How to use notifyDataSetChanged on CustomAdapter?
Why hibernate runs delete and insert commands for embaddable objects
Allow JComboBox to accept List<String> or HashMap instead of String[]
Integrated authentication failed on JDBC connection to SQLEXPRESS with Windows authentication
Why the other languages rather than java is not platform independent? [closed]
Parsing XML file from URL into Array
How to shutdown static threadpools?
Calendar offset issue
Determining Alphanumerics using char?
Is there any rest testing tool which hosts the webservices and injects mocks in the facade layer?

Categories

HOME
java
xamarin
testng
mediawiki
ngrx
kde
relative-path
electron
mvvmcross
uber-api
vifm
quickbooks
circuit
dosgi
fatal-error
ef-migrations
invantive-sql
database-replication
evopdf
scichart
immutable.js
amazonsellercentral
opencover
extjs5
microsoft-r
java-7
vlsi
objectanimator
fabric8
ioio
amazon-kinesis-kpl
git-merge
swift3.0.2
jna
hue
squib
mapzen
sfdc
core-plot
jvm-languages
glew
node-gyp
businessworks
apple-news
hendrix
pnotify
sage-one
sonarlint-vs
mediaelement
objective-c-swift-bridge
dstu2-fhir
pcf
mongocsharpdriver
player
pervasive-sql
qtableview
msys
cartesian-product
feedback
security-testing
embedded-code
ami
census
sonarqube5.1.2
facebook-graph-api-v2.4
file-copying
googlemock
valueconverter
openlaszlo
page-layout
dataservice
back-stack
sqlperformance
pygit2
gdata-api
bubble-chart
eclipse-templates
coercion
cinema-4d
gdlib
gin
nhibernate.search
vc90
xetex
commodore

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App