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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:17:50+00:00 2026-06-09T11:17:50+00:00

I am having a question with Jackson that I think should be simple to

  • 0

I am having a question with Jackson that I think should be simple to solve, but it is killing me.

Let’s say I have a java POJO class that looks like this (assume Getters and Setters for me):

class User {
    private String name;
    private Integer age;
}

And I want to deserialize JSON that looks like this into a User object:

{
  "user":
    {
      "name":"Sam Smith",
      "age":1
  }
}

Jackson is giving me issues because the User is not the first-level object in the JSON. I could obviously make a UserWrapper class that has a single User object and then deserialize using that but I know there must be a more elegant solution.

How should I do this?

  • 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-09T11:17:51+00:00Added an answer on June 9, 2026 at 11:17 am

    edit: this solution only works for jackson < 2.0

    For your case there is a simple solution:

    • You need to annotate your model class with @JsonRootName(value = "user");
    • You need to configure your mapper with om.configure(Feature.UNWRAP_ROOT_VALUE, true); (as for 1.9) and om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); (for version 2).

    That’s it!


    @JsonRootName(value = "user")
    public static class User {
        private String name;
        private Integer age;
    
        public String getName() {
            return name;
        }
    
        public void setName(final String name) {
            this.name = name;
        }
    
        public Integer getAge() {
            return age;
        }
    
        public void setAge(final Integer age) {
            this.age = age;
        }
    
        @Override
        public String toString() {
            return "User [name=" + name + ", age=" + age + "]";
        }
    
    }
    
    ObjectMapper om = new ObjectMapper();
    om.configure(Feature.UNWRAP_ROOT_VALUE, true);
    System.out.println(om.readValue("{  \"user\":    {      \"name\":\"Sam Smith\",      \"age\":1  }}", User.class));
    

    this will print:

    User [name=Sam Smith, age=1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is pretty simple, but I am having a hard time finding any
Hey stupid question but I'm having a hard time connecting my java program to
I have a general question about data templates in WPF. Let's say I have
After having my last question answered , I have never see the preventDefault(); function
I am just getting into Sharepoint, and I have a question about having a
Perhap this is a simple basic question Having an enum public enum TK{ ID,GROUP,DATA,FAIL;
I am having this question that really puzzles me, here it goes: If I
Just a simple question,having this: fftw_complex *H_cast; H_cast = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*M*N); what is the
I've seen a few different versions of this question but having difficulty applying it
i have a quick question about having a reference to a subset of a

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.