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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:52:07+00:00 2026-06-17T08:52:07+00:00

I have this object structure which I’m trying to annotate with Jackson to marshal/unmarshal

  • 0

I have this object structure which I’m trying to annotate with Jackson to marshal/unmarshal to a JSON file.

public class A {
    List<B> bList;
}

public class B {
    String attr;
    Map<String, C> map;
}

public class C {
    @JsonIgnore
    String name;
    String value;
}

A has a list of B‘s and B has a map of C‘s where the key of the map is the name attribute of C. I want the JSON to look like this if possible:

{
    "bList" : [
               {
                   "attr":"itsValue"
                   "KEY_IN_MAP":"VALUE_IN_C",
                   "KEY_2_IN_MAP":"VALUE_2_IN_C"
               }
               ]
}

Where KEY_IN_MAP is the name of C as the key in B‘s map and VALUE_IN_C is the value of the value object in the map. I’ve tried annotating a put method for the map:

@JsonAnySetter
private void put(String name, C value) {
    map.put(name, c);
}

But marshaling this gives me:

{
    "bList" : [
               {
                   "attr":"itsValue"
                   "KEY_IN_MAP": {
                       "value":"VALUE_IN_C",
                   },
                   "KEY_2_IN_MAP": {
                       "value":"VALUE_2_IN_C"
                   }
               }
               ]
}

Is there any way to get the above mapping with Jackson or any other JSON serializing library? My goal is to get rid of the redundancy of writing "value" every time and compress the file as much as possible.

The map in B could be turned into a list of C but I still need the mapping to be

{"name" : "value"} for each object C
  • 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-17T08:52:08+00:00Added an answer on June 17, 2026 at 8:52 am

    Here are few suggestions that I have:

    1. Make your Map<String,C> to be a Map<String,String>.
    2. You can also make your Map<String,C> to be List<C>.

    Please have a look at the other thread which discusses the same.

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

Sidebar

Related Questions

I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
I have the following structure: class foo(object): class bar(object): def __init__(self, parent): self._parent=parent #this
I have this object: class a { public string Application; public DateTime From, To;
I have a data structure object which is loaded from an XML file inside
I have this simple structure: 1 parent, and two different childs. public class Parent{}
I have an interesting problem Here is the object structure public class Testdata {
I have this class in my parser.py file class HostInfo(object): def __init__(self, host_id): self.osclass
I have a data.table object like this one library(data.table) a <- structure(list(PERMNO = c(10006L,
I have an NSArray full of NSDictionary object. This structure is built from a
I have this object which is an instance of a superclass. I want 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.