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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:32:00+00:00 2026-05-27T11:32:00+00:00

I am getting an error for the following code in a java web app–

  • 0

I am getting an error for the following code in a java web app–

         XStream xstream = new XStream();  
         apiresponse myClassObject;
         myClassObject= xstream.fromXML(resp);  

The error is shown for the line of code just above this line–
error=”Type mismatch- cannot convert from Object to apiresponse”

Given below is the XML that I have to parse—

<apiresponse version="1" xmlns="http://ahrefs.com/schemas/api/links/1">
 <resultset_links count="2">
  <result>
    <source_url>http://ahrefs.com/robot/</source_url>
    <destination_url>http://blog.ahrefs.com/</destination_url>
    <source_ip>50.22.24.236</source_ip>
    <source_title>Ahrefs – backlinks research tool</source_title>
    <visited>2011-08-31T07:56:53Z</visited>
    <anchor>Blog</anchor>
    <rating>257.674000</rating>
    <link_type>text</link_type>
    <is_nofollow>false</is_nofollow>
  </result>
  <result>
    <source_url>http://apps.vc/</source_url>
    <destination_url>http://ahrefs.com/robot/</destination_url>
    <source_ip>64.20.55.86</source_ip>
    <source_title>Device info</source_title>
    <visited>2011-08-27T18:59:31Z</visited>
    <anchor>http://ahrefs.com/robot/</anchor>
    <rating>209.787100</rating>
    <link_type>text</link_type>
    <is_nofollow>false</is_nofollow>
  </result>
 </resultset_links>
</apiresponse>

I have created the following java classes to obtain data from above xml—

package com.arvindikchari.linkdatasmith.domain;

final public class apiresponse {  

  protected resultset_links rlinks;  


  public apiresponse() {

  }

  public resultset_links getRlinks()
  {
    return rlinks;
  }

  public setRlinks(resultset_links rlinks)
    {
        this.rlinks=rlinks;
    }


}  



final public class resultset_links {  

    protected List<result> indiv_result = new ArrayList<result>();

  public resultset_links() {

  }


  public List<result> getIndiv_result()
  {

    return List;
  }


  public  void setIndiv_result(List<result> indiv_result)
    {

        this.indiv_result=indiv_result;
    }

}  

final public class result {

   protected String source_url;
   protected String destination_url;
   protected String source_ip;
   protected String source_title;
   protected String visited;
   protected String anchor;
   protected String rating;
   protected String link_type;

public result() {

}

public String getSource_url()
{

return source_url;
}

public void setSource_url(String source_url)
{

this.source_url=source_url;
}

public String getDestination_url()
{

return destination_url;
}

public void setDestination_url(String destination_url)
{

this.destination_url=destination_url;
}

public String getSource_ip()
{

return source_ip;
}

public void setSource_ip(String source_ip)
{

    this.source_ip=source_ip;
}


public String getSource_title()
{

return source_title;
}

public void setSource_title(String source_title)
{

this.source_title=source_title;
}


public String getVisited()
{

return visited;
}

public void setVisited(String visited)
{

this.visited=visited;
}


public String getAnchor()
{

return anchor;
}

public void setAnchor(String anchor)
{ 

this.anchor=anchor;
}


public String getRating()
 {

return rating;
 }

public void setRating(String rating)
{ 

this.rating=rating;
}


public String getLink_type()
{

return link_type;
}

public void setLink_type(String link_type)
{

    this.link_type=link_type;
}


}

What am I doing wrong here?

  • 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-27T11:32:01+00:00Added an answer on May 27, 2026 at 11:32 am

    You have many errors, but the one corresponding to your message is you have to cast the result of xstream.fromXML to an apiresponse’ object :

    apiresponse result = (apiresponse)xstream.fromXML(resp);
    

    Moreover, the code you provided (the Java classes) do not compile, there are many errors.

    Here are some improvements :

    Result.java :

    @XStreamAlias("result")
    public class Result {
    
       protected String source_url;
       protected String destination_url;
       protected String source_ip;
       protected String source_title;
       protected String visited;
       protected String anchor;
       protected String rating;
       protected String link_type;
       protected Boolean is_nofollow;
    
    public Result() {
    
    }
    
    public String getSource_url()
    {
    
    return source_url;
    }
    
    public void setSource_url(String source_url)
    {
    
    this.source_url=source_url;
    }
    
    public String getDestination_url()
    {
    
    return destination_url;
    }
    
    public void setDestination_url(String destination_url)
    {
    
    this.destination_url=destination_url;
    }
    
    public String getSource_ip()
    {
    
    return source_ip;
    }
    
    public void setSource_ip(String source_ip)
    {
    
        this.source_ip=source_ip;
    }
    
    
    public String getSource_title()
    {
    
    return source_title;
    }
    
    public void setSource_title(String source_title)
    {
    
    this.source_title=source_title;
    }
    
    
    public String getVisited()
    {
    
    return visited;
    }
    
    public void setVisited(String visited)
    {
    
    this.visited=visited;
    }
    
    
    public String getAnchor()
    {
    
    return anchor;
    }
    
    public void setAnchor(String anchor)
    {
    
    this.anchor=anchor;
    }
    
    
    public String getRating()
     {
    
    return rating;
     }
    
    public void setRating(String rating)
    {
    
    this.rating=rating;
    }
    
    
    public String getLink_type()
    {
    
    return link_type;
    }
    
    public void setLink_type(String link_type)
    {
    
        this.link_type=link_type;
    }
    
    public Boolean getIs_nofollow() {
        return is_nofollow;
    }
    
    public void setIs_nofollow(Boolean is_nofollow) {
        this.is_nofollow = is_nofollow;
    }
    

    ResultsetLinks.java :

    @XStreamAlias("resultset_links")
    public class ResultsetLinks {
    
    @XStreamImplicit(itemFieldName="result")
    protected List<Result> indivResult = new ArrayList<Result>();
    
      public ResultsetLinks() {
    
      }
    
      public List<Result> getResult()
      {
    
        return indivResult;
      }
    
    
      public  void setResult(List<Result> indiv_result)
        {
    
            this.indivResult =indiv_result;
        }
    
    }
    

    ApiResponse.java :

    @XStreamAlias("apiresponse")
    public class ApiResponse {
    
    @XStreamAlias("resultset_links")
    protected ResultsetLinks rlinks;
    
    
    public ApiResponse() {
    
    }
    
    public ResultsetLinks getRlinks()
    {
        return rlinks;
    }
    
    public void setRlinks(ResultsetLinks rlinks)
      {
        this.rlinks=rlinks;
      }
    

    }

    And finally your code to unmarshall the XML :

        XStream xstream = new XStream();
        xstream.processAnnotations(ApiResponse.class);
        xstream.processAnnotations(ResultsetLinks.class);
        xstream.processAnnotations(Result.class);
    
        ApiResponse result = (ApiResponse)xstream.fromXML(resp);
    

    All this code is working fine with Xstream 1.4.2

    Try to follow Sun’s coding convention for your classes name, attributes names, etc…
    Use XstreamAliases to adapt the Java class name to the XML name.

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

Sidebar

Related Questions

Getting error with the following code: import java.util.Scanner; public class FahrenheitToCelsius{ public static void
Can anyone tell me why am i getting error message java.lang.NullPointerException in following code??
While running the following code i am getting the error java.lang.OutOfMemoryException : java heap
I'm getting the following error with some Java code I've written: internal error; cannot
Getting the above error in following code. How to rectify it. Thanks. Please look
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
With the following code, I keep getting error C2535 when I compile. It's complaining
I'm getting the error message when running the following code from a C# console
Why am I getting an undefined label error in following code? (I am leaving
I am trying to compile the following code and i am getting the error:

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.