Note that there are some explanatory texts on larger screens.

plurals
  1. POjava- unable to map object returned by query to correctly defined class
    primarykey
    data
    text
    <p>I have a requirement where some data has to be obtained by connecting to an API.</p> <p>I have mapped the object returned by query to a hashmap, using the following code--</p> <pre><code> untypedResult=wt.QueryPermissions(); resp.getWriter().println(" Response for QueryPermissions----"); if(wt.errormsg=="No Error") { hMap = (HashMap&lt;String, Integer&gt;) 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()); </code></pre> <p>The output as returned by using above code --</p> <pre><code> Response for QueryPermissions---- get_all_words_popularity : {keyphrase_limit=999, timeout_limit=99, cost_per_call=99, result_limit=999} </code></pre> <p>Now I tried to map the response (in object) to the following class---</p> <pre><code>public class wt_queryperm_class { public Integer keyphrase_limit; public Integer timeout_limit; public Integer cost_per_call; public Integer result_limit; } </code></pre> <p>Also, now I modified the code used to display the data as shown below--</p> <pre><code> //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&lt;String, Integer&gt;) 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 ); } </code></pre> <p>However I get the following error when I run the above code--</p> <pre><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 </code></pre> <p>What am I doing wrong here? How do I cast the response correctly so that I can extract each of the 4 values correctly?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload