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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:57:00+00:00 2026-05-23T19:57:00+00:00

I read some tutorials that say that a simple bean should be defined with

  • 0

I read some tutorials that say that a simple bean should be defined with getter and setter methods representing the JSON data in a systematic way.

Given below is the data that I will have to parse- pls help me by defining the bean for this type of situation (where one node contains many nodes, each of which contain distinct sub nodes)

I require from_title, from_url, to_title and to_url for approx 2500 records out of the JSON output.

—————-JSON DATA SAMPLE—————————-

{
"NOTICE" : [...terms of use appear here...]
"links" : [
{
"anchor_has_img" : false,
"anchor_text" : "",
"exclude" : false,
"follow" : true,
"from_host_rank10" : 3.48817529303454,
"from_ip" : "66.96.130.51",
"from_ip_geo" : {
"city" : "Burlington",
"country_code" : "US",
"isp_org" : "The Endurance International Group",
"latitude" : "42.5051",
"longitude" : "-71.2047",
"state" : "MA",
"zip" : "01803"
},
"from_pubdate" : 1287298800,
"from_rank10" : 4.1e-05,
"from_title" : "Antique Links",
"from_url" : "http://www.100tonsofstuff.com/links-antiquesresources.
htm",
"to_http_status" : 301,
"to_rank10" : 8.97651069961698,
"to_redir" : "http://geocities.yahoo.com/",
"to_title" : "Get a web site with easy-to-use site building tools -
Marengo Inn - Los Angeles Hotel - Yahoo - GeoCities",
"to_url" : "http://www.geocities.com/"
},
[...2499 entries skipped for this example...]
"nlinks_avail" : 2500,
"nlinks_est_total" : 11630.5708745538,
"to_rank10" : 8.97651069961698
}
  • 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-23T19:57:01+00:00Added an answer on May 23, 2026 at 7:57 pm

    Here’s what I’d do.

    import java.io.File;
    import java.io.FileInputStream;
    import java.math.BigDecimal;
    import java.net.URI;
    import java.util.Date;
    import java.util.List;
    
    import org.codehaus.jackson.JsonNode;
    import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
    import org.codehaus.jackson.annotate.JsonProperty;
    import org.codehaus.jackson.map.MapperConfig;
    import org.codehaus.jackson.map.ObjectMapper;
    import org.codehaus.jackson.map.PropertyNamingStrategy;
    import org.codehaus.jackson.map.introspect.AnnotatedField;
    import org.codehaus.jackson.map.introspect.AnnotatedMethod;
    
    public class Foo
    {
      public static void main(String[] args) throws Exception
      {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setPropertyNamingStrategy(new CamelCaseToLowerCaseWithUnderscoresNamingStrategy());
        mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY));
    
        Response response = mapper.readValue(new File("input.json"), Response.class);
        String json = mapper.writeValueAsString(response);
        System.out.println(json);
    
        // Check for correctness
        JsonNode originalInput = mapper.readTree(new FileInputStream("input.json")); // next release of Jackson will have readTree that just takes a File object reference
        JsonNode generatedOutput = mapper.readTree(json);
        System.out.println("Are they the same?");
        System.out.println(originalInput.equals(generatedOutput) ? "yes" : "no");
      }
    }
    
    class Response
    {
      @JsonProperty("NOTICE")
      String notice;
      List<Link> links;
      int nlinksAvail;
      BigDecimal nlinksEstTotal;
      BigDecimal toRank10;
    }
    
    class Link
    {
      boolean anchorHasImg;
      String anchorText;
      boolean exclude;
      boolean follow;
      BigDecimal fromHostRank10;
      String fromIp;
      Geo fromIpGeo;
      Date fromPubdate;
      BigDecimal fromRank10;
      String fromTitle;
      URI fromUrl;
      int toHttpStatus;
      BigDecimal toRank10;
      URI toRedir;
      String toTitle;
      URI toUrl;
    }
    
    class Geo
    {
      String city;
      String countryCode;
      String ispOrg;
      String latitude;
      String longitude;
      State state;
      String zip;
    }
    
    enum State
    {
      MA, MN, NJ
    }
    
    class CamelCaseToLowerCaseWithUnderscoresNamingStrategy extends PropertyNamingStrategy
    {
      @Override  
      public String nameForGetterMethod(MapperConfig<?> config,  
          AnnotatedMethod method, String defaultName)  
      {  
        return translate(defaultName);  
      }  
    
      @Override  
      public String nameForSetterMethod(MapperConfig<?> config,  
          AnnotatedMethod method, String defaultName)  
      {  
        return translate(defaultName);  
      }  
    
      @Override  
      public String nameForField(MapperConfig<?> config,  
          AnnotatedField field, String defaultName)  
      {  
        return translate(defaultName);  
      }  
    
      private String translate(String defaultName)  
      {  
        char[] nameChars = defaultName.toCharArray();  
        StringBuilder nameTranslated =  
            new StringBuilder(nameChars.length * 2);  
        for (char c : nameChars)  
        {  
          if (Character.isUpperCase(c))  
          {  
            nameTranslated.append("_");  
            c = Character.toLowerCase(c);  
          }  
          nameTranslated.append(c);  
        }  
        return nameTranslated.toString();  
      }
    }
    

    I might also figure out an enum for the country codes.

    Of course, the fields would actually be private.

    A more complete PropertyNamingStrategy is available at http://jira.codehaus.org/browse/JACKSON-598.

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

Sidebar

Related Questions

I've read some MVC advice in the past regarding models stating that you should
I've made some unit tests (in test class). The tutorial I've read said that
I read some properties from an xml file, amongst which is a string that
I just started with ASP.NET MVC 1.0. I've read through some tutorials but I
I recently started learning Emacs . I went through the tutorial, read some introductory
I read some of the answers on here re: testing views and controllers, and
I read some source code of ZenTest but didn't find where it is implemented.
I've read some about .egg files and I've noticed them in my lib directory
So far I've read some blog articles about cloud computing and services for hosting
I need to read some large files (from 50k to 100k lines), structured in

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.