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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:22:47+00:00 2026-05-26T15:22:47+00:00

I have a requirement where some data has to be obtained by connecting to

  • 0

I have a requirement where some data has to be obtained by connecting to an API.

I have mapped the object returned by query to a hashmap, using the following code–

        untypedResult=wt.QueryPermissions();
        resp.getWriter().println(" Response for QueryPermissions----");
        if(wt.errormsg=="No Error")
        {   
            hMap = (HashMap<String, Integer>) untypedResult;

            Set set = hMap.entrySet();

            Iterator i = set.iterator();

            while(i.hasNext()){
              Map.Entry me = (Map.Entry)i.next();
              resp.getWriter().println(me.getKey() + " : " +     me.getValue());

The output as returned by using above code —

 Response for QueryPermissions----
 get_all_words_popularity : {keyphrase_limit=999, timeout_limit=99, cost_per_call=99, result_limit=999}

Now I tried to map the response (in object) to the following class—

public class wt_queryperm_class {

public Integer keyphrase_limit;
public Integer timeout_limit;
public Integer cost_per_call;
public Integer result_limit;


}

Also, now I modified the code used to display the data as shown below–

    //declare new object to store result of QueryPermissions
        wt_queryperm_class a;

    untypedResult=wt.QueryPermissions();
        resp.getWriter().println(" Response for QueryPermissions----");
        if(wt.errormsg=="No Error")
        {   
            hMap = (HashMap<String, Integer>) untypedResult;

            Set set = hMap.entrySet();

            Iterator i = set.iterator();

            while(i.hasNext()){
              Map.Entry me = (Map.Entry)i.next();
              a= (wt_queryperm_class)(me.getValue());
              resp.getWriter().println(me.getKey() + " :  Cost per call=" + a.cost_per_call + "Keyphrase limit=" + a.keyphrase_limit + " Result limit=" + a.result_limit +" Timeout limit=" +  a.timeout_limit );
            }

However I get the following error when I run the above code–

Problem accessing /keywords_trial_application. Reason:

java.util.HashMap cannot be cast to com.taurusseo.keywords.wt_queryperm_class
Caused by:

java.lang.ClassCastException: java.util.HashMap cannot be cast to com.taurusseo.keywords.wt_queryperm_class

What am I doing wrong here? How do I cast the response correctly so that I can extract each of the 4 values correctly?

  • 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-26T15:22:48+00:00Added an answer on May 26, 2026 at 3:22 pm

    The result of the query, given what’s printed and the error you got is a Map<String, Map<String, Integer>> (or a Map<String, Map<String, String>> if the numbers are stored as Strings).

    The map has one single key : "get_all_words_popularity". The associated valud contains 4 keys : "keyphrase_limit", "timeout_limit", "cost_per_call", "result_limit".

    So your code should rather look like this:

    untypedResult = wt.queryPermissions();
    resp.getWriter().println(" Response for QueryPermissions----");
    if("No Error".equals(wt.errormsg)) {   
        Map<String, Map<String, Integer> hMap = 
            (Map<String, Map<String, Integer>) untypedResult;
    
        for (Map.Entry<String, Map<String, Integer>> me : hMap.entrySet()) {
            Map<String, Integer> value = me.getValue();
            WtQueryPerm perm = new WtQueryPerm(value.get("keyphrase_limit"),
                                               value.get("timeout_limit"),
                                               value.get("cost_per_call"),
                                               value.get("result_limit"));
            resp.getWriter().println(me.getKey() 
                                     + " :  Cost per call=" + perm.getCostPerCall() 
                                     + ", Keyphrase limit=" + perm.getKeyphraseLimit() 
                                     + ", Result limit=" + perm.getResultLimit() 
                                     + ", Timeout limit=" +  perm.getTimeoutLimit());
    
        }
    }
    

    Note that my code

    • respects the Java naming conventions
    • always uses generic types, which avoid casts and compilation warnings
    • doesn’t compare Strings with ==, but uses equals, because == only compares the references and not the values.
    • declare the variables with the smaller scope possible, only when needed.
    • use getters to access the state of the constructed object.

    Also understand that a cast doesn’t magically transform an object into another object type. It just allows referencing an object of type A as another type B, and only works if the object is effectively of type B (and thus B has A as ancestor or interface)

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

Sidebar

Related Questions

We have the requirement to take a form submission and save some data, then
I have a requirement to send some 100 bytes data over internet .My machine
I have the following requirement: Based on some user input, I need to generate
I have a requirement where I need to send some data from my server
I have the following Query and i need the query to fetch data from
I'm using NServiceBus to handle some calculation messages. I have a new requirement to
I have a dynamic data ASP.NET application with a requirement to give some users
I have a requirement to do some imports from an Excel spread sheet and
I have a requirement to create a simple database in Access to collect some
I have a requirement on my new project to serve up some hidden assets

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.