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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:18:39+00:00 2026-06-12T09:18:39+00:00

I’m trying to deserialize json to a java entity, but I’m having trouble getting

  • 0

I’m trying to deserialize json to a java entity, but I’m having trouble getting Jackson to deserialize an json array to a Pair[]. Pair is a custom class but it follows the standard form found on SO :

public class Pair<K, V> {

private final K k;
private final V v;

public Pair(K k, V v) {
    this.k = k;
    this.v = v;
}

public K getKey() {
    return k;
}

public V getValue() {
    return v;
}
...
}

The Json object can be changed as needed, but I’m trying to use something of the form:

{"priority":1,"account":"012345","tld":"com","name":"domain_check","params":[{"key":"domain","value":"domain.com"}]}

My “DefaultRequest” entity class contains:

@Entity
public class DefaultRequest implements Serializable, Comparable, Request {

//other fields...

private Pair[] params;

@Override
public Pair[] getParams() {
    return params;
}

@Override
public void setParams(Pair[] params) {
    this.params = params;

//other methods...
}
}

I’m sorry if someone has answered this already. I’m admittedly new to using jackson, but I’ve spent almost 3 days on this and I have a deadline. I also have to believe someone has had to deserialize to an entity containing a Pair[] before. Any ideas are welcome. I have complete flexibility in changing both the json format and the entity class if there is a better alternative.
Thanks in advance!

  • 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-12T09:18:40+00:00Added an answer on June 12, 2026 at 9:18 am

    Question is bit vague, so I might be wrong, but you may be looking for the annotation to tell Jackson how to use a custom constructor to pass data. If so:

    @JsonCreator
    public Pair(@JsonProperty("key") K k,
       @JsonProperty("value") V v) {
        ...
    }
    

    This will work for all kinds of types, not just primitives, nor does it try to guess what goes where. Annotations for names are needed only because JDK does not add argument names in bytecode, so they are not available, unlike method names.

    EDIT:

    Looks like a transformation is needed. So how about this:

    @JsonCreator
    public Pair(Map<String,String> json)
    {
       Map.Entry<String,String> en = json.entrySet().iterator().next();
       key = en.getKey();
       value = en.getValue();
    }
    
    @JsonValue
    public Map<String,String> asMap() {
      Map<String,String> m = new HashMap<String,String>();
      m.put(key, value);
      return m;
    }
    

    Bit more code, but allows conversions to intermediate types. For what it’s worth, Jackson 2.1 will include standard “delegating” serializer/deserializer, to make it possible to define a Converter that encapsulates such logic.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.