views:

30

answers:

1

I have 2 web services declared in 2 different packages in java

package com.HelloWorld

@WebService(targetNamespace="http://www.xyz.com/Hello")
@SOAPBinding(parameterStyle = ParameterStyle.WRAPPED, style = Style.DOCUMENT, use = Use.LITERAL)
{

  public class Hello
  {

   @WebMethod
   @WebResult(name="SayHelloResult", targetNamespace="http://www.xyz.com/Hello")

   Public HelloData SayHello()
   {

       HelloData data = new HelloData();
        // Some work
        return data;
   }
  }
}


package com.HelloWorld2

@WebService(targetNamespace="http://www.xyz.com/Hello2")
@SOAPBinding(parameterStyle = ParameterStyle.WRAPPED, style = Style.DOCUMENT, use = Use.LITERAL)
{

  public class Hello2
  {

   @WebMethod
   @WebResult(name="SayHelloResult", targetNamespace="http://www.xyz.com/Hello2")

 Public HelloData SayHello2()
   {

      com.Hello helloObject = new com.Hello.HelloWorld();

      com.Hello.HelloObject helloData= helloObject.SayHello();

      // need to clone helloData to com.HellowWorld2 type object

      // return a com.HelloWorld2.HelloData object
   }
  }
}

As shown in the above example, a call to SayHello2 redirects the call to another webmethod. Although HelloData in both the packages are similar, they are defined in different namespaces. How can I do a deep copy from one object to another?

A: 

You cannot deep copy an Object of type Foo into an Object of type Bar. If Foo is a super class of Bar and is a concrete class, technically you can do it, but it's advised that you not do this in Effective Java.

Amir Afghani