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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:54:17+00:00 2026-06-12T05:54:17+00:00

I am looking JAXB annotation class which can be serialized the following json format.

  • 0

I am looking JAXB annotation class which can be serialized the following json format.
JSON Format : {"name":"xyz","attr1":"attr1value","attr2":"attr2value",.....}}
In above JSON format, name is a mandatory attribute,
others are not but user should be able to pass as much as attributes.

The below JaxB annotation class which can be serialized the JSON format
{"name":"xyz","openContentMap":{"attr1":"attr1value","attr2":"attr2value", so on}}.
But we want to JaxB annotation which can be serialized this format {"name":"xyz","attr1":"attr1value","attr2":"attr2value",.....}}

@XmlRootElement
public class MyJaxbBean  {

private String name;
private Map<String, String> openContentMap = new HashMap<String, String>();

@XmlAnyElement
public Map<String, String> getOpenContentMap() {
    return openContentMap;
}

@XmlAnyElement
public void setOpenContentMap(String key, String value) {
    openContentMap.put(key, value);
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public MyJaxbBean() {   
}

}

  • 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-12T05:54:18+00:00Added an answer on June 12, 2026 at 5:54 am

    Use org.codehaus.jackson.annotate.JsonAnyGetter and org.codehaus.jackson.annotate.JsonAnySetter

    @XmlRootElement
    public class MyJaxbBean
    {
       private String name;
    
       private Map<String, String> openContentMap = new HashMap<String, String>();
    
       public String getName()
       {
          return name;
       }
    
       public void setName(String name)
       {
          this.name = name;
       }
    
       @JsonAnyGetter
       public Map<String, String> getOpenContentMap()
       {
          return openContentMap;
       }
    
       @JsonAnySetter
       public void add(final String key, final String value)
       {
          openContentMap.put(key, value);
       }
    }  
    

    works well

      String json = "{\"name\":\"xyz\",\"attr1\":\"attr1value\",\"attr2\":\"attr2value\"}";
      MyJaxbBean agr = new ObjectMapper().readValue(json, MyJaxbBean.class);
      System.out.println(agr.getName() + " " + agr.getOpenContentMap());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for C# class which wraps calls to do the following: read and write
Is there a JAXB annotation to ignore a parent class, when you have an
Looking at some assembly code for x86_64 on my Mac, I see the following
Looking at the Ehcahce implementation of net.sf.cache.JS107, I am trying to achieve the following
Looking around at different code bases I see a variety of styles: Class interfaces
I have the following model class MyClass { id someRandomString } I would like
Looking for an equivalent container class that matches to C#'s Arraylist collections class. Is
How do I have JAXB preserve nulls when receiving a JSON sting that contains
Looking at the following code, does theme[sprite].img get nested inside result[definition].data (as theme[sprite].img is
Looking at the last demo for the .change() jQuery function. Can someone explain to

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.