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 8296855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:11:00+00:00 2026-06-08T15:11:00+00:00

Hello I had this follow json code. [{check:{domain:qwe.coedu.br}},{check:{domain:qwe.com.br}},{check:{domain:qwe.com}}] How do to convert this json

  • 0

Hello I had this follow json code.

[{"check":{"domain":"qwe.coedu.br"}},{"check":{"domain":"qwe.com.br"}},{"check":{"domain":"qwe.com"}}]"

How do to convert this json in my object

class Check {String domain , String status ...}

It return a List<Check>, but the Check attributes are null. See my code. with Gson.

Gson gson = new Gson();
    Type fooType = new TypeToken<Collection<Check>>(){}.getType();
    System.out.println(((List<Check>)gson.fromJson("[{\"check\":{\"status\":\"2\",\"domain\":\"william.com.br\"}}]", fooType)).get(0).getDomain());

When I debug my returned list, this contains all objects in list, but all with your attributes null.

What is wrong ?

  • 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-08T15:11:02+00:00Added an answer on June 8, 2026 at 3:11 pm

    You need a customized converter, because you have a list of objects that holds a property named check. And this property is of a class that has the properties domain and status.

    Two possibilities here:

    1. if you don’t want to change the Json format, or you simply can’t probably write your own JsonDeserializer, in which you will instanciate your Check object and then set the properties by your own is the best choice;
    2. or you could modify your check class in order to hold a check property of a type that holds a property named domain and another one status.

    For the second case is pretty clear what needs to be done, but for the first case you could do something like:

    import java.lang.reflect.Type;
    import java.util.Collection;
    
    import com.google.gson.Gson;
    import com.google.gson.GsonBuilder;
    import com.google.gson.JsonDeserializationContext;
    import com.google.gson.JsonDeserializer;
    import com.google.gson.JsonElement;
    import com.google.gson.JsonObject;
    import com.google.gson.JsonParseException;
    import com.google.gson.reflect.TypeToken;
    
    public class GsonTestClass {
    
        static class MyDeserializer implements JsonDeserializer<Check> {
    
            public Check deserialize(JsonElement arg0, Type arg1,
                    JsonDeserializationContext arg2) throws JsonParseException {
                JsonObject jsonObject = arg0.getAsJsonObject().get("check").getAsJsonObject();
                // this code could be improved with null checks and so on...
                return new Check( //
                        jsonObject.get("domain").getAsString(), //
                        jsonObject.get("status").getAsString() //
                );
            }
    
        }
    
        public static void main(String args[]) {
            Gson gson = new GsonBuilder().registerTypeAdapter(Check.class, new MyDeserializer()).create();
            String json = "[{\"check\":{\"status\":\"2\",\"domain\":\"william.com.br\"}}]";
            Type fooType = new TypeToken<Collection<Check>>() {}.getType();
            System.out.println((gson.fromJson(json, fooType)));
        }
    
        static class Check {
    
            private String domain;
            private String status;
    
            public Check() {
            }
    
            public Check(String domain, String status) {
                super();
                this.domain = domain;
                this.status = status;
            }
    
            public String getDomain() {
                return domain;
            }
    
            public void setDomain(String domain) {
                this.domain = domain;
            }
    
            public String getStatus() {
                return status;
            }
    
            public void setStatus(String status) {
                this.status = status;
            }
    
            @Override
            public String toString() {
                return "Check: " + domain + " - " + status;
            }
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had this code trace in my Razor view @{ string markerPlacementScript = alert('Hello');
hello i had this code and it worked well: private void Textparsing() { using
Say if I had a string which had this text/html stored in it: Hello.
Hello i had implemented this code Using your own SQLite database in Android applications
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
If I had an html string containing this somewhere in the middle of it:
Hello everyone this is my first post on stack overflow.com I am trying to
Hello I had this problem: and to solve it I included reset.css form here
Hello I've got this query to get users by email, which is an unique
Hello i had a simple copy file program in C but i cant explain

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.