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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:56:45+00:00 2026-06-07T12:56:45+00:00

I would like to use this kind of Objects with json: class Message{ int

  • 0

I would like to use this kind of Objects with json:

class Message{
    int code;
    String user;
    Map<List<String>, List<String>> profile;
}

it seems json can’t handle Object keys as array, so I would need to tranfer them like that:

{
"code": 1,
"user": "John",
"profile": {
    "type,1": ["tester"],
    "lang,2": ["fr", "it", "en", "sp"],
    "rate,4": ["10", "1000"],
    "date,5": ["134118329", "1341973211"]

    }
}

or

{
"code": 1,
"user": "John",
"profile": {
    "type": [1,"tester"],
    "lang": [2,"fr", "it", "en", "sp"],
    "rate": [4,"10", "1000"],
    "date": [5,"134118329", "1341973211"]

    }
}

the first json is probably simpler, even if it relies on a hard string separator,

So with the first one it seems I have to write this huge adapter:

private static class MyAdapter implements JsonSerializer<Map<List<String>, List<String>>>,
        JsonDeserializer<Map<List<String>, List<String>>> {

    @Override   
    public JsonElement serialize(Map<List<String>, List<String>> m,
            Type type, JsonSerializationContext context) {

        JsonObject j = new JsonObject();
        for (Entry<List<String>, List<String>> e : m.entrySet() ){
            JsonArray jj=new JsonArray();
            for (String s : e.getValue()){
                jj.add(new JsonPrimitive(s));
            }
            j.add(e.getKey().get(0)+","+e.getKey().get(1), jj);
        }
        return j;
    }

    @Override
    public Map<List<String>, List<String>> deserialize(JsonElement json, Type type,
            JsonDeserializationContext arg2) throws JsonParseException {

        Map<List<String>, List<String>> m = new HashMap<List<String>, List<String>>();

        JsonObject jObject = json.getAsJsonObject();
        for (Entry<String, JsonElement> e : jObject.entrySet() ){
            List<String> key = new ArrayList<String>();
            List<String> value = new ArrayList<String>();
            for (String s : e.getKey().split(",") ){
                key.add(s);
            }
            for (JsonElement jj : e.getValue().getAsJsonArray() ){
                value.add(jj.getAsString());
            }
            m.put(key, value);
        }
        return m;
    }
}

…

GsonBuilder g = new GsonBuilder();
    g.registerTypeAdapter(Map.class, new MyAdapter());
    Gson gson = g.create();

Is there faster ways? I guess yes, the idea is just to split the key into a Map composite key, because each part of the key has an important meaning

thx, and sry for the edit

  • 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-07T12:56:48+00:00Added an answer on June 7, 2026 at 12:56 pm

    This will not work.

    Object declaration syntax according specification:

    An object is an unordered set of name/value pairs. An object begins
    with { (left brace) and ends with } (right brace). Each name is
    followed by : (colon) and the name/value pairs are separated by ,
    (comma).

    This:

    {
        ["type", 1]: "tester",
        ["lang", 2]: ["fr", "it", "en", "sp"],
        ["rate", 4]: ["10", "1000"],
        ["date", 5]: ["134118329", "1341973211"]
    
    }
    

    is invalid, and therefore you can’t read with Gson causing the following exception: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING

    the name in front of json: aRequest = is invalid too.

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

Sidebar

Related Questions

I would like to use this script https://github.com/jeromeetienne/jquery-qrcode (or is there even a better
So, I would like to use this magic find function in my CakePHP 2.0
I would like to change this: // use appropiate lang.xx.php file according to the
I would like to use the Guice in my remote servlet but encountered this
I know this is very basic. I would like to use jQuery to change
I'm stumped by this seemingly trivial problem... I would like to use python to
Instead of app-id@appspot.com or any@app-id.appspot.com I would like to use any@own-domain.tld. can this be
I would like to do something like this i.e., use wild card characters in
This is really just for my own use: I would like to be able
I use Microsoft Visual SourceSafe for version control. I would like to change this

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.