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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:00:16+00:00 2026-06-02T01:00:16+00:00

I have a Json response which looks like the following: { data: [ {

  • 0

I have a Json response which looks like the following:

{
    "data": [
        {
            "param1": "value1",
            "param2": "value2",
                    .
                    .
                    .
            "paramN": "valueN"
        }
    ]
}

I don’t know the name and the number of the parameters. So, I need and want to bind all these parameters to a java.util.Map field consisting of <“paramX”, “valueX”> tuples. To do this, I tried the following code but “parametersMap” field returns null.

@XmlRootElement(name="data")
@XmlAccessorType(XmlAccessType.FIELD)
public class Parameters {
    @XmlElement
    private Map<String,String> parametersMap;

    // Getter and setter for parametersMap
}

How can I achieve such a binding with JAXB annotations?

Thanks in advance.

  • 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-02T01:00:18+00:00Added an answer on June 2, 2026 at 1:00 am

    Basically you need an xml adapter. You can fiddle with the names on the KeyValue class to get the specific output you desire.

    Parameter.java

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
    import java.util.Map;
    
    @XmlRootElement(name = "data")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Parameters {
    
        @XmlJavaTypeAdapter(value = Adapter.class)
        private Map<String, String> parametersMap;
    
        // Getter and setter for parametersMap
    }
    

    Adapter.java

    import javax.xml.bind.annotation.adapters.XmlAdapter;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    
    public class Adapter extends XmlAdapter<List<KeyValue>, Map<String, String>> {
    
        @Override
        public Map<String, String> unmarshal(List<KeyValue> v) throws Exception {
            Map<String, String> map = new HashMap<>(v.size());
            for (KeyValue keyValue : v) {
                map.put(keyValue.key, keyValue.value);
            }
            return map;
        }
    
        @Override
        public List<KeyValue> marshal(Map<String, String> v) throws Exception {
            Set<String> keys = v.keySet();
            List<KeyValue> results = new ArrayList<>(v.size());
            for (String key : keys) {
                results.add(new KeyValue(key, v.get(key)));
            }
            return results;
        }
    }
    

    KeyValue.java Put better JAXB tags here, obviously.

    import javax.xml.bind.annotation.XmlType;
    
    @XmlType
    public class KeyValue {
        public KeyValue() {
        }
    
        public KeyValue(String key, String value) {
            this.key = key;
            this.value = value;
        }
    
        //obviously needs setters/getters
        String key;
        String value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a chunk of JSON which looks something like: { map: [ [
I have a working json service which looks like this: @POST @Path(/{id}/query) @Consumes(MediaType.APPLICATION_JSON) @Produces(JSON)
I have a JSON response that looks like this. I want to extract the
We have a JSON response which can contain null values (e.g. { myValue: null
I have a url which have a response in Json lon=-0.1275&pg=0 I parsed the
I have the following JSON object: { response: { status: 200 }, messages: [
In my servlet I have the following code: response.setContentType(application/json);//set json content type PrintWriter out
I am using jquery-tmpl and receiving the following JSON data, which I am using
I have a JSON response which contains a timestamp, but I'm having some issues
I am using Ext.data.Store to call a PHP script which returns a JSON response

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.