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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:03:33+00:00 2026-06-11T10:03:33+00:00

I’m having trouble getting this bit of JSON into a POJO. I’m using Jackson

  • 0

I’m having trouble getting this bit of JSON into a POJO. I’m using Jackson configured like this:

protected ThreadLocal<ObjectMapper> jparser = new ThreadLocal<ObjectMapper>();

    public void receive(Object object) {
    try { 
        if (object instanceof String && ((String)object).length() != 0) {
            ObjectDefinition t = null ; 
            if (parserChoice==0) { 
                if (jparser.get()==null) {
                    jparser.set(new ObjectMapper());
                }
                t = jparser.get().readValue((String)object, ObjectDefinition.class);
            }

            Object key = t.getKey();
            if (key == null)
                return;
            transaction.put(key,t); 
        } 
    } catch (Exception e) { 
        e.printStackTrace();
    }
}

Here’s the JSON that needs to be turned into a POJO:

{
    "id":"exampleID1",
    "entities":{
      "tags":[
         {
            "text":"textexample1",
            "indices":[
               2,
               14
            ]
         },
         {
            "text":"textexample2",
            "indices":[
               31,
               36
            ]
         },
         {
            "text":"textexample3",
            "indices":[
               37,
               43
            ]
         }
      ]
}

And lastly, here’s what I currently have for the java class:

    protected Entities entities;
@JsonIgnoreProperties(ignoreUnknown = true)
protected class Entities {
    public Entities() {}
    protected Tags tags;
    @JsonIgnoreProperties(ignoreUnknown = true)
    protected class Tags {
        public Tags() {}

        protected String text;

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }
    };

    public Tags getTags() {
        return tags;
    }
    public void setTags(Tags tags) {
        this.tags = tags;
    }
};
//Getters & Setters ...

I’ve been able to translate the more simple objects into a POJO, but the list has me stumped.

Any help is appreciated. Thanks!

  • 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-11T10:03:34+00:00Added an answer on June 11, 2026 at 10:03 am

    I think your issue is with your class definition. It seems that you wish that the Tags class contains the raw text from Json, which is an array. What I would do instead:

    protected Entities entities;
    @JsonIgnoreProperties(ignoreUnknown = true)
    protected class Entities {
        public Entities() {}
        @JsonDeserialize(contentAs=Tag.class)
        protected List<Tag> tags;
    
        @JsonIgnoreProperties(ignoreUnknown = true)
        protected class Tag {
            public Tag() {}
    
            protected String text;
    
            public String getText() {
                return text;
            }
    
            public void setText(String text) {
                this.text = text;
            }
        };
    
        public Tags getTags() {
            return tags;
        }
        public void setTags(Tags tags) {
            this.tags = tags;
        }
    };
    

    Here on the field tags I use a List to represent the Json array, and I tell Jackson to deserialize the content of that list as the Tag class. This is required because Jackson doesn’t have the runtime information of the generic declaration. You’d do the same thing for the indices, namely have a field List<Integer> indices with the JsonDeserialize annotation.

    • 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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace

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.