Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8203587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:36:33+00:00 2026-06-07T07:36:33+00:00

I have a problem while parsing a json with Gson. here is my code:

  • 0

I have a problem while parsing a json with Gson.
here is my code:

Gson gson = new GsonBuilder().create();
String json = gson.toJson(myMap.values());
MyClass clazz = gson.fromJson(json, MyClass.class);
System.out.println(clazz.toString());

But I get the next error(I also tried with new TypeToken, but the errors are the same):

com.google.gson.JsonParseException: The JsonDeserializer MapTypeAdapter failed to deserialized json object /*here is json object*/

Caused by: java.lang.IllegalArgumentException: Map objects need to be parameterized unless you use a custom serializer. Use the com.google.gson.reflect.TypeToken to extract the ParameterizedType.
    at com.google.gson.TypeInfoMap.<init>(TypeInfoMap.java:45)
    at com.google.gson.DefaultTypeAdapters$MapTypeAdapter.deserialize(DefaultTypeAdapters.java:605)
    at com.google.gson.DefaultTypeAdapters$MapTypeAdapter.deserialize(DefaultTypeAdapters.java:573)
    at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:50)

here is obtained json string, it’s valid(but may be I should remove the “items” substring?):

["{\n 
    \"items\": 
        [
        \n  {
        \n \"MyClass_type_var1\": {
        \n    \"field1\": \"val1\",
        \n    \"field2\": \"val2\",
        \n    \"field3\": [
                        \n     {
                        \n      \"subfield1\": subval
                        \n     }
                        \n    ]
                        \n   }
                        \n  },
        \n \"MyClass_type_var2\": {
        \n    \"field1\": \"val1\",
        \n    \"field2\": \"val2\",
        \n    \"field3\": [
                        \n     {
                        \n      \"subfield1\": subval
                        \n     }
                        \n    ]
                        \n   }
                        \n  },
        \n \"MyClass_type_var3\": {
        \n    \"field1\": \"val1\",
        \n    \"field2\": \"val2\",
        \n    \"field3\": [
                        \n     {
                        \n      \"subfield1\": subval
                        \n     }
                        \n    ]
                        \n   }
                        \n  },


etc......   may I haven't closed brackets correctly, but they are correct :)                
            }           
        ]               
    "]                  

I would be grateful to any pieces of advice.

public final class MyClass extends GenericJson {

  private String field1;
  private String field2;
  private java.util.List<AClass> field3; // has subfield1
//getters and setters
}

single-line json:

["{\n \"items\": [ \n  { \n \"MyClass\": { \n    \"field1\": \"val1\", \n    \"field2\": \"val2\", \n    \"field2\": [ \n  { \n \"subfield1\": subval   \n } \n    ] \n   } \n  }, \n \"MyClass\": { \n    \"field1\": \"val1\", \n    \"field2\": \"val2\", \n    \"field2\": [ \n     {  \n      \"subfield1\": subval \n     } \n    ] \n   } \n  }, \n \"MyClass\": {\n   \"field1\":\"val1\", \n    \"field2\": \"val2\", \n    \"field2\": [ \n     { \n      \"subfield1\": subval \n     } \n    ] \n   } \n  }, }          ]   "]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:36:36+00:00Added an answer on June 7, 2026 at 7:36 am

    here i’ve tried to use jackon, but it didn’t helped. see the answer for that question(used my own parser).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have a problem while pasting my contents (or text) generated by Java code
I have some problem with JSON parsing. When I hit URL, I've got JSON
i have a problem while building and running an iphone application.Im using xml parsing
I have a problem with parsing my JSon Data in an Android application. I
My team and I have this nasty problem with parsing a string received from
I am using google gson-2.2.1 library for parsing large response of JSON. I have
I have a problem in C while parsing the argv Variable. This is the
I have problem while loading data into html select when users press or click
I have problem while using jquery maskedinput with asp.net textbox. I have a check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.