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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:54:35+00:00 2026-05-27T07:54:35+00:00

With Jackson json library, it is possible to deserialize object through the use of

  • 0

With Jackson json library, it is possible to deserialize object through the use of the @JsonCreator, and be given the “top level” map representing the input json, as follows:

class MyClass {
    final int field;

    @JsonCreator
    public MyClass(Map<String, Object> map) {
        this.field = (int) map.get("theInt");
    }
}

or even on a static factory method:

class MyClass {
    final int field;

    public MyClass(int theInt) {
        this.field = theInt;
    }

    @JsonCreator
    static MyClass create(Map<String, Object> map) {
        return new MyClass((int) map.get("theInt"));
    }
}

The previous examples can process the following kind of json input:

{
    "key1":"value1",
    "key2":"value2",
    "key3":"value3"
}

This is particularly useful in my case because I would like to deserialize a json which structure I don’t know. Being given access to what I call the “top level map” makes things simple.

I would like to deserialize my objects this way as it also allows to create immutable objects, instead of using @JsonAnySetter which doesn’t permit this, and @JsonProperty which I can’t use as I don’t know the properties name in advance as I mentioned earlier.

Then to go further, I would like to inject some configuration in my factory method, and Jackson allows this through the use of @JacksonInject and a call to withInjectableValues(InjectableValues) on the ObjectMapper.

This is eventually the kind of code I would like to use:

class MyClass {
    final MyField[] myFields;

    public MyClass(MyField... myFields) {
        this.myFields = myFields;
    }

    @JsonCreator
    static MyClass create(@JacksonInject("conf") Conf conf, Map<String, Object> map) {
        MyFields[] myFields;
        // initialize myFields (or any other object) based on the content of map
        // and also make use of the inject conf
        return new MyClass(myFields);
    }
}

Unfortunately, Jackson throws the following kind of exceptions:

  • when trying the trick on the constructor

JsonMappingException: Argument #1 of constructor [constructor for MyClass, annotations: {JsonCreator=@JsonCreator()}] has no property name annotation; must have name when multiple-paramater constructor annotated as Creator

  • when trying the trick on the factory method

JsonMappingException: Argument #1 of factory method [method create, annotations: {JsonCreator=@JsonCreator()}] has no property name annotation; must have when multiple-paramater static method annotated as Creator

Does anyone know how I could solve the problem?

To sum up the requirements, I need:

  • access to the top level map (don’t know the json property names in advance)
  • to create an immutable object (so can’t use @JsonAnySetter)
  • to inject some conf to the @JsonCreator decorated constructor or factory method

I cannot change the json input format, which looks like this:

{
    "key1":"value1",
    "key2":"value2",
    "key3":"value3"
}

[EDIT]

This is a known issue: http://jira.codehaus.org/browse/JACKSON-711 (not fixed yet)

  • 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-05-27T07:54:36+00:00Added an answer on May 27, 2026 at 7:54 am

    Right, you would like to both use “delegating” creator (single argument, into which JSON input is first bound) — different from “property-based” creator where set of named parameters are passed — and injectable value(s). This should ideally work, but I think it might not work currently.
    I think there is a Jira entered for this, so you can check it (http://jira.codehaus.org/browse/JACKSON) out.

    Just to make sure: are you using version 1.9.2? There have been some fixes in this are since 1.9.0; which at least would give better error message.

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

Sidebar

Related Questions

I need to deserialize a GeoJSON JSON object with the Jackson library. In this
Is it possible to use Jackson as the serializer/marshaller for JSON data instead of
I'm having trouble getting Jackson to correctly deserialize json into an object when calling
I'm trying to use Jackson to deserialize some JSON originally created using Jackson. The
I am trying to deserialize/map the below JSON to List<Bill > java object using
I want to use jackson json library for a generic method as follows: public
I'm using the Jackson library to create JSON objects, but when I use the
I use jackson for converting JSON to Object class. JSON: { aaa:111, bbb:222, ccc:333
I have a problem with my custom JSON deserializer. I use Jackson to map
I have a Java servlet, where I want to use the Jackson JSON parser

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.