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

  • Home
  • SEARCH
  • 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 6138805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:54:41+00:00 2026-05-23T17:54:41+00:00

I’m having troubles with the deserialization of a Json: I get this error: No-args

  • 0

I’m having troubles with the deserialization of a Json:

I get this error:

“No-args constructor for class Categoria: does not exist. Register an InstanceCreator with Gson for this type to fix this problem”

public class getElements  {

String [] getEl (String url) throws ClientProtocolException, IOException {

    Categoria c = null;
    Categoria[] cArray = null;
    String [] c1Array = null;
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://10.0.2.2:3000/"+url);

    HttpResponse response = client.execute(request);
    HttpEntity entity = response.getEntity();
    String stringa = "{\"categorium\":{\"created_at\":\"2011-06-09T08:57:41Z\",\"c1\":\"rete stradale\",\"updated_at\":\"2011-06-09T08:57:41Z\",\"id\":1}}";

     Gson json=new Gson();
      try{
          cArray=json.fromJson(stringa, Categoria[].class);
          Log.i("ELEMENTO", ""+cArray);
      }catch(JsonParseException e){
          Log.i("error","JsonParseException");
      }

      c1Array = new String[cArray.length];
      for (int i=0; i<cArray.length; i++) {
          c1Array[i] = cArray[i].c1;
      }

    return c1Array;


 }
}

Categorium class:

public class Categoria {
    public String created_at;
    public String c1;
    public String updated_at;
    public int id;

    public Categoria() {
        this.created_at = "";
        this.c1="";
        this.updated_at = "";
        this.id = 0;
    }

}

This is the Json. I want to bring al the “c1” into a String array, to built a snippet!

[
    {
        "categorium": {
            "created_at": "2011-06-09T08:57:41Z",
            "c1": "rete stradale",
            "updated_at": "2011-06-09T08:57:41Z",
            "id": 1
        }
    },
    {
        "categorium": {
            "created_at": "2011-06-09T13:50:29Z",
            "c1": "servizi pubblici",
            "updated_at": "2011-06-09T13:50:29Z",
            "id": 2
        }
    },
    {
        "categorium": {
            "created_at": "2011-06-09T13:50:37Z",
            "c1": "illuminazione",
            "updated_at": "2011-06-09T13:50:37Z",
            "id": 3
        }
    },
    {
        "categorium": {
            "created_at": "2011-06-09T13:50:46Z",
            "c1": "inquinamento",
            "updated_at": "2011-06-09T13:50:46Z",
            "id": 4
        }
    },
    {
        "categorium": {
            "created_at": "2011-06-09T13:50:54Z",
            "c1": "vandalismo",
            "updated_at": "2011-06-09T13:50:54Z",
            "id": 5
        }
    },
    {
        "categorium": {
            "created_at": "2011-06-09T13:51:00Z",
            "c1": "abbandono",
            "updated_at": "2011-06-09T13:51:00Z",
            "id": 6
        }
    },
    {
        "categorium": {
            "created_at": "2011-06-15T08:33:17Z",
            "c1": "altro",
            "updated_at": "2011-06-15T08:33:17Z",
            "id": 8
        }
    }
]
  • 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-05-23T17:54:42+00:00Added an answer on May 23, 2026 at 5:54 pm

    Answer to latest version of question:

    import java.util.Arrays;
    
    import com.google.gson.Gson;
    
    public class Foo
    {
      public static void main(String[] args) throws Exception
      {
        new getElements().getEl();
      }
    }
    
    class CategoriumContainer
    {
      Categorium categorium;
    
      @Override
      public String toString()
      {
        return String.format("{CategoriumContainer: categorium=%s}", categorium);
      }
    }
    
    class Categorium
    {
      public String created_at;
      public String c1;
      public String updated_at;
      public int id;
    
      @Override
      public String toString()
      {
        return String.format("{%s, %s, %s, %s}", created_at, c1, updated_at, id);
      }
    }
    
    class getElements
    {
      String[] getEl() throws Exception
      {
        String stringa = "[{\"categorium\":{\"created_at\":\"2011-06-09T08:57:41Z\",\"c1\":\"rete stradale\",\"updated_at\":\"2011-06-09T08:57:41Z\",\"id\":1}}, {\"categorium\":{\"created_at\":\"2011-06-09T13:50:29Z\",\"c1\":\"servizi pubblici\",\"updated_at\":\"2011-06-09T13:50:29Z\",\"id\":2}}, {\"categorium\":{\"created_at\":\"2011-06-09T13:50:37Z\",\"c1\":\"illuminazione\",\"updated_at\":\"2011-06-09T13:50:37Z\",\"id\":3}}, {\"categorium\":{\"created_at\":\"2011-06-09T13:50:46Z\",\"c1\":\"inquinamento\",\"updated_at\":\"2011-06-09T13:50:46Z\",\"id\":4}}, {\"categorium\":{\"created_at\":\"2011-06-09T13:50:54Z\",\"c1\":\"vandalismo\",\"updated_at\":\"2011-06-09T13:50:54Z\",\"id\":5}}, {\"categorium\":{\"created_at\":\"2011-06-09T13:51:00Z\",\"c1\":\"abbandono\",\"updated_at\":\"2011-06-09T13:51:00Z\",\"id\":6}}, {\"categorium\":{\"created_at\":\"2011-06-15T08:33:17Z\",\"c1\":\"altro\",\"updated_at\":\"2011-06-15T08:33:17Z\",\"id\":8}}]";
    
        Gson json = new Gson();
        CategoriumContainer[] results = json.fromJson(stringa, CategoriumContainer[].class);
        System.out.println(Arrays.toString(results));
        // output:
        // [{CategoriumContainer: categorium={2011-06-09T08:57:41Z, rete stradale, 2011-06-09T08:57:41Z, 1}}, {CategoriumContainer: categorium={2011-06-09T13:50:29Z, servizi pubblici, 2011-06-09T13:50:29Z, 2}}, {CategoriumContainer: categorium={2011-06-09T13:50:37Z, illuminazione, 2011-06-09T13:50:37Z, 3}}, {CategoriumContainer: categorium={2011-06-09T13:50:46Z, inquinamento, 2011-06-09T13:50:46Z, 4}}, {CategoriumContainer: categorium={2011-06-09T13:50:54Z, vandalismo, 2011-06-09T13:50:54Z, 5}}, {CategoriumContainer: categorium={2011-06-09T13:51:00Z, abbandono, 2011-06-09T13:51:00Z, 6}}, {CategoriumContainer: categorium={2011-06-15T08:33:17Z, altro, 2011-06-15T08:33:17Z, 8}}]
    
        String[] c1Array = new String[results.length];
        for (int i = 0; i < results.length; i++)
        {
          c1Array[i] = results[i].categorium.c1;
        }
        System.out.println(Arrays.toString(c1Array));
        // output: [rete stradale, servizi pubblici, illuminazione, inquinamento, vandalismo, abbandono, altro]
    
        return c1Array;
      }
    }
    

    Answer to original version of question:

    That’s a terrible error message from Gson for the situation. I suggest logging an issue with them.

    As posted in the current version of the question, the problem is you’re trying to deserialize a JSON object as an array. Easy solutions to this problem are to either change the JSON into an array, or deserialize it as an object.

    Here’s an example that changes the JSON to have an array, and changes other things into what I guess you’re trying to achieve.

    import java.util.Arrays;
    
    import com.google.gson.Gson;
    
    public class Foo
    {
      public static void main(String[] args) throws Exception
      {
        new getElements().getEl();
      }
    }
    
    class Thing
    {
      Categoria[] categorium;
    
      @Override
      public String toString()
      {
        return Arrays.toString(categorium);
      }
    }
    
    class Categoria
    {
      public String created_at;
      public String c1;
      public String updated_at;
      public int id;
    
      public Categoria()
      {
        this.created_at = "";
        this.c1 = "";
        this.updated_at = "";
        this.id = 0;
      }
    
      @Override
      public String toString()
      {
        return String.format("{%s, %s, %s, %s}", created_at, c1, updated_at, id);
      }
    }
    
    class getElements
    {
      String[] getEl() throws Exception
      {
        String stringa = "{\"categorium\":[{\"created_at\":\"2011-06-09T08:57:41Z\",\"c1\":\"rete stradale\",\"updated_at\":\"2011-06-09T08:57:41Z\",\"id\":1},{\"created_at\":\"2011-07-12T08:57:41Z\",\"c1\":\"asdf fdsa\",\"updated_at\":\"2011-07-12T08:57:41Z\",\"id\":2}]}";
    
        Gson json = new Gson();
        Thing thing = json.fromJson(stringa, Thing.class);
        System.out.println(thing);
        // output:
        // [{2011-06-09T08:57:41Z, rete stradale, 2011-06-09T08:57:41Z, 1}, {2011-07-12T08:57:41Z, asdf fdsa, 2011-07-12T08:57:41Z, 2}]
    
        Categoria[] cArray = thing.categorium;
    
        String[] c1Array = new String[cArray.length];
        for (int i = 0; i < cArray.length; i++)
        {
          c1Array[i] = cArray[i].c1;
        }
        System.out.println(Arrays.toString(c1Array));
        // output: [rete stradale, asdf fdsa]
    
        return c1Array;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.