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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:59:21+00:00 2026-06-07T05:59:21+00:00

Using JAXB, how to map <entry key=childResources> below? I tried mapping it to a

  • 0

Using JAXB, how to map <entry key="childResources"> below?

I tried mapping it to a Map, to a list of @XmlRootElement anotated classes and other ways, without success.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<map>    
  <entry key="extraProperties">        
    <map>            
      <entry key="methods">                
        <list>                    
          <map>                        
            <entry key="name" value="GET" />
          </map>                    
          <map />                    
          <map>                        
            <entry key="name" value="POST" />                        
            <entry key="messageParameters">                            
              <map>                                
                <entry key="id">                                    
                  <map>                                        
                    <entry key="acceptableValues" value="" />                                        
                    <entry key="optional" value="false" />                                        
                    <entry key="defaultValue" value="" />                                        
                    <entry key="type" value="string" />
                  </map>                                
                </entry>                                
                <entry key="enabled">                                    
                  <map>                                        
                    <entry key="acceptableValues" value="" />                                        
                    <entry key="optional" value="true" />                                        
                    <entry key="defaultValue" value="true" />                                        
                    <entry key="type" value="boolean" />
                  </map>                                
                </entry>                                
                <entry key="factoryclass">                                    
                  <map>                                        
                    <entry key="acceptableValues" value="" />                                        
                    <entry key="optional" value="false" />                                        
                    <entry key="defaultValue" value="" />                                        
                    <entry key="type" value="string" />
                  </map>                                
                </entry>                                
                <entry key="description">                                    
                  <map>                                        
                    <entry key="acceptableValues" value="" />                                        
                    <entry key="optional" value="true" />                                        
                    <entry key="defaultValue" value="" />                                        
                    <entry key="type" value="string" />
                  </map>                                
                </entry>                                
                <entry key="target">                                    
                  <map>                                        
                    <entry key="acceptableValues" value="" />                                        
                    <entry key="optional" value="true" />                                        
                    <entry key="defaultValue" value="server" />                                        
                    <entry key="type" value="string" />
                  </map>                                
                </entry>                                
                <entry key="property">                                    
                  <map>                                        
                    <entry key="acceptableValues" value="" />                                        
                    <entry key="optional" value="true" />                                        
                    <entry key="defaultValue" value="" />                                        
                    <entry key="type" value="string" />
                  </map>                                
                </entry>                                
                <entry key="restype">                                    
                  <map>                                        
                    <entry key="acceptableValues" value="" />                                        
                    <entry key="optional" value="false" />                                        
                    <entry key="defaultValue" value="" />                                        
                    <entry key="type" value="string" />
                  </map>                                
                </entry>                            
              </map>                        
            </entry>                    
          </map>                
        </list>            
      </entry>            
      <entry key="commands">                
        <list />
      </entry>            
      <entry key="childResources">                
        <map>                    
          <entry key="ab/cd" value="http://localhost:4848/management/domain/resources/custom-resource/ab%2Fcd" />                    
          <entry key="xx" value="http://localhost:4848/management/domain/resources/xx" />
        </map>            
      </entry>        
    </map>    
  </entry>    
  <entry key="message" value="" />    
  <entry key="exit_code" value="SUCCESS" />    
  <entry key="command" value="custom-resource" />
</map>
  • 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-07T05:59:22+00:00Added an answer on June 7, 2026 at 5:59 am

    The java.util.Map interface has no provider to marshal/unmarshal its instances. You’ll have to write a class that extends XmlAdapter and annotate the java.util.Map attribute with @XmlJavaTypeAdapter(MyMapAdapter.class).

    After a while on Google looking for jax-rs java.util.map, I ended up with the codes bellow. In my case I have named my adapter as XmlStringMapAdapter instead of MyMapAdapter.

    ServiceDefinition.java

    @XmlRootElement(name = "entry")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class ServiceDefinition {
    
        @XmlAttribute
        private String key;
    
        @XmlJavaTypeAdapter(XmlStringMapAdapter.class)
        private Map<String, String> map = new HashMap<String, String>();
    
        // getters & setters
    }
    

    EntryElement.java

    public class EntryElement {
    
        @XmlAttribute public String key;
        @XmlAttribute public String value;
    
        public EntryElement() {}
    
        public EntryElement(String key, String value) {
            this.key = key;
            this.value = value;
        }
    }
    

    MapElement.java

    @XmlRootElement(name = "map")
    public class MapElement {
    
        @XmlElement(name = "entry")
        public List<EntryElement> entries = new ArrayList<EntryElement>();
    
        public void addEntry(String key, String value) {
            entries.add(new EntryElement(key, value));
        }
    
    }
    

    XmlStringMapAdapter.java

    public class XmlStringMapAdapter extends XmlAdapter<MapElement, Map<String, String>> {
    
        @Override
        public MapElement marshal(Map<String, String> v) throws Exception {
    
            if (v == null || v.isEmpty()) {return null;}
    
            MapElement map = new MapElement();
    
            for (String key : v.keySet()) {
                map.addEntry(key, v.get(key));
            }
    
            return map;
        }
    
        @Override
        public Map<String, String> unmarshal(MapElement v) throws Exception {
            if (v == null) {return null;}
    
            Map<String, String> map = new HashMap<String, String>(v.entries.size());
    
            for(EntryElement entry: v.entries) {
                map.put(entry.key, entry.value);
            }
    
            return map;
        }
    
    }
    

    And bellow is a class that I used to test the new map adapter.

    ServiceResouce.java

    @Path("service")
    public class ServiceResource {
    
        @Context
        private UriInfo uriInfo;
    
        @GET
        @Path("definition")
        @Produces("application/xml")
        public Response getDefinition() {
            ServiceDefinition def = new ServiceDefinition();
            UriBuilder b = uriInfo.getBaseUriBuilder();
    
            def.setKey("childResources");
            def.getMap().put("ab/cd", b.path("ab/cd").build(this).getPath());
            def.getMap().put("xx", b.path("xx").build(this).getPath());
    
            return Response.ok(def).build();
        }
    }
    

    Output from the resource above is as shown bellow.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <entry key="childResources">
        <map>
            <entry key="ab/cd" value="http://localhost:8080/management/resources/ab/cd" />
            <entry key="xx" value="http://localhost:8080/management/resources/xx" />
        </map>
    </entry>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Jackson to serialize a JAXB annotated object into a map object.
I am using jaxb maven plugin to generate classes from schemas. I have 3
I am creating a SOAP service using JAX-WS and JAXB, by annotating the classes.
Using JAXB to generate XML binding classes. The schema is based on a set
We are using JAXB to generate Java classes and have encountered a few cases
i am trying to generate schema using jaxb from my exisitng POJO classes and
I want to explicitly map fields in my classes to XML, so I'm using
I'm using JAXB to generate a XML Schema from my Java classes so the
I want to generate Java classes from a dtd file using JAXB. The dtd
I am using JAXB XMLadapter to marshal and unmarshal Boolean values. The application's XML

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.