Re: Casting Object to NSArray
Re: Casting Object to NSArray
- Subject: Re: Casting Object to NSArray
- From: Hsu <email@hidden>
- Date: Sat, 28 Jun 2003 18:09:42 -0700
First, if the class type is java.lang.Object, something isn't working
the way you think it is. You can try to see what's going on by using
TCPMonitor.app (/Developer/Examples/JavaWebObjects). - start your
server, grab the wsdl, fix the URLs for the port set in TCPMonitor and
take a look at the XML going across.
Object[] returnArray = (Object[]) invoke();
NSArray returnNSArray = new NSArray(returnArray);
You cannot cast between objects of different types. Casting is only
used to tell the compiler "even though you cannot infer the _actual
runtime_ type of this object, I can and I'm telling you that the
_actual runtime_ type is XX". Casting cannot change the type of an
object.
Karl
On Saturday, June 28, 2003, at 05:06 PM, Goodbye Bill wrote:
Karl / Art,
I DID do as Art requested. The object returned "java.lang.Object" and
not
NSArray. I could not successfully cast it to an NSArray and/or use it.
That is the whole problem.
If it was an "Object[]" I would assume that I should be able to simply
pull
out individual objects from THAT array. Is that not correct? Even
better,
I would like to be able to change it back to an NSArray.
Is it possible to cast an "Object[]" to an "NSArray?" If so, how?
Also,
should I be able to use the "Object[]" directly?
Sorry for being a pain. I swear that I am following your replies
letter-for-letter.
Thanks,
"Bill"
On 6/28/03 4:03 AM, "Hsu" <email@hidden> wrote:
Art is correct. There are several classes that have serializers but no
deserializers - NSArray is one of them. In goes an NSArray, out comes
an Object[].
Karl
On Friday, June 27, 2003, at 08:18 PM, Art Isbell wrote:
On Friday, June 27, 2003, at 04:35 PM, Goodbye Bill wrote:
Thanks for all of the replies, however I left out one small detail
that will
probably change all of your answers: this is via a web service.
The code on the SERVER (the WebService) looks like this...
private NSArray myObjects;
public NSArray GetObjects()
{
return myObjects;
}
The code on the CLIENT (the consumer app) looks like this...
public NSArray myReceivedObjects()
{
Object tmpArray = serviceClient().invoke(serviceName(),
"GetObjects", null);
return (NSArray)tmpArray;
}
Here's a little more info on this:
1. The "serviceClient" is a "WOWebServiceClient" object;
2. According to the API Reference, the "invoke" method on this
object
returns an "Object" regardless of what method it invokes on the
server.
The client example above will compile but generates a
"ClassCastException"
exception at runtime.
Any ideas? I'm going on two full days working with this. The
bottom
line
is that I need to get an array of objects from a web service.
The documentation for invoke() states, "This method may return either
an object, or a language array of objects." I read "language array
of
objects" to mean an Object[] (i.e., a primitive Java array) rather
than an NSArray. Apparently you didn't do what I suggested: print
tmpArray.getClass().getClassName() to see what class of object is
returned.
Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
--
If I want to hear the pitter patter of little feet, I'll put shoes on
my cat.
Homepage:
http://homepage.mac.com/khsu/index.html
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
--
O frabjous day! Kahlo! Erte!"
He chortled in his joy.
Homepage:
http://homepage.mac.com/khsu/index.html
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.