GSON throwing Expected BEGIN OBJECT but was BEGIN ARRAY

0 votes

When I am trying to parse a JSON object into a list of object, I am getting an exception like, java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2

Is there any way to fix it?

Dec 26, 2018 in Java by Daisy
• 8,110 points

1 answer to this question.

–1 vote

This will work:

ChannelSearchEnum[] enums = gson.fromJson(yourJson, ChannelSearchEnum[].class);

But this is better:

Type collectionType = new TypeToken<Collection<ChannelSearchEnum>>(){}.getType();
Collection<ChannelSearchEnum> enums = gson.fromJson(yourJson, collectionType);
answered Dec 26, 2018 by Sushmita
• 6,900 points
copied comment without citing
Without citing? What are you trying to say?

Related Questions In Java

0 votes
0 answers

Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 63 path $.data

Here i am using retrofit post request:- RequestBody ...READ MORE

Apr 23, 2020 in Java by anonymous
• 120 points
0 votes
1 answer

Following error is occurring "Can't start Eclipse - Java was started but returned exit code=13"

There are combinations of Operating System, JDK ...READ MORE

answered Apr 19, 2018 in Java by Rishabh
• 3,640 points
0 votes
2 answers

When I am running eclispe on my computer it is throwing error. How to resolve it?

If you have downloaded the 64 bit ...READ MORE

answered Dec 10, 2018 in Java by Sushmita
• 6,900 points
0 votes
1 answer

JSON parsing in Java using Gson

Well, you can easily do that by ...READ MORE

answered Nov 21, 2018 in Java by code.reaper12
• 3,500 points
+1 vote
0 answers

output occurs but invisible immediately how to rectify this ?

public class evenodd { public static void main(String[] ...READ MORE

Oct 17, 2019 in Java by BIPLAB
• 130 points
0 votes
1 answer

How can we get the current location in Android?

First you need to define a LocationListener to handle ...READ MORE

answered Sep 25, 2018 in Java by Parth
• 4,630 points
0 votes
1 answer

Can't find class CognitoUserPoolsSignInProvider: Issue with Sign In integration

CognitoUserPoolsSignInProvider is ditributed as part of aws-android-sdk-auth-userpools library. Please import ...READ MORE

answered Sep 28, 2018 in AWS by Priyaj
• 58,120 points
0 votes
1 answer

How to Read/Write String from a File in Android

Writing a File in android: private void writeToFile(String ...READ MORE

answered Oct 3, 2018 in Java by sharth
• 3,350 points