Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Unable to Overload toString for Object Date: Wed, 12 Feb 2014 13:57:59 -0500 Organization: A noiseless patient Spider Lines: 62 Message-ID: References: <705891c8-b170-44c0-866f-48eec7b38c4d@googlegroups.com> <1138f80c-bc7c-4edd-a91b-fb5f8e2137d6@googlegroups.com> <0163eae2-3f35-4b96-a292-87a2fe3d3b03@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 12 Feb 2014 18:57:59 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="858a9d65d95f4ea4d355bd116aa2cdbf"; logging-data="2804"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/p4MnwAaFdMJtQnlP9q7Xd" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: Cancel-Lock: sha1:fhNBM8dCTWUWJFayXVSO+r+r4Ts= Xref: csiph.com comp.lang.java.programmer:27492 On 2/12/2014 1:37 PM, markspace wrote: > On 2/12/2014 12:38 AM, Ojesh Dugar wrote: >> Basically, I am able to access Bugzilla Webservice API through java >> code(xmlrpc) and in return i get a object of <> java.util.HashMap>>. According to Bugzilla documentation two items >> are returned, bugs and faults, both are array of hashes and I want to >> access these. Thanks. >> > > > Cast to a HashMap and iterate over all of its keys. > > (not tested): > > // create bug > Object createResult = rpcClient.execute("Bug.search", new > Object[]{bugMap}); > //createResult.toString(); > > HashMap bugs = (HashMap)createResult; > for( Object key : bugs.keySet() ) { > System.out.println( "Key "+key.getClass().getName() > + "= "+key > + ", value "+ bugs.get( key ).getClass().getName() > + "= "+ bugs.get( key ) > ); > } > > More info here: > > http://www.mkyong.com/java/how-to-loop-a-map-in-java/ This probably won't work as written. The original post said createResult.toString() produced "[Ljava.lang.Object;@2ee5e48a", indicating that rpcClient.execute() returns an Object[], that is, an array of Object references. (To those surprised that an array of Objects is itself an Object: Someday it will all make sense, I promise.) So what he needs to do is cast the returned value to an Object[]: Object[] array = (Object[]) createResult; ... then iterate over the contents of the array: for (Object obj : array) { ... and then (assuming the Objects in the array are HashMaps as advertised, or in any case *some* kind of Maps): Map bugs = (Map) obj; ... and *then* he can iterate over the entries, either in the manner markspace shows or by using the key/value pairs directly: for (Map.Entry ent : bugs.entrySet()) { Object key = ent.getKey(); Object val = ent.getValue(); ... -- Eric Sosman esosman@comcast-dot-net.invalid