lausd-teacher / gwt-gdata

Automatically exported from code.google.com/p/gwt-gdata
0 stars 0 forks source link

Unable to retrieve Attibute values #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. request SnippetEntries to GData housing:
 SnippetsQuery query = SnippetsQuery.newInstance(itemsFeedUri);
 query.setBq("[item
type:housing][location:@-37.727+144.592..@-37.680+144.823651]");
 query.setContent("attributes,thumbnails,geocodes");

2. Try retrieve attributes:
 snippet.getAttributes().get("image_link").getValue()
3. It causes Hosted Browser and Eclipse fail with:
java.lang.ClassCastException: java.lang.String
    at com.google.gwt.core.client.JsArray$.get$(JsArray.java)
    at com.google.gwt.gdata.client.impl.ArrayHelper.toArray(ArrayHelper.java:145)
    at com.google.gwt.gdata.client.impl.Map$.values$(Map.java:105)

What is the expected output? What do you see instead?
Expect to see an Attribute object (or array of those actually). Instead the
ClassCastException is thrown.

What version of the product are you using? On what operating system?
gwt-gdata-1.10.1 on OS X Leopard 10.5.8

Please provide any additional information below.
From what I understand there are multiple "image_link" attributes (ie.
keys) and Map expects unique keys. Not sure if that is in any way related.

Original issue reported on code.google.com by dean.mas...@gmail.com on 16 Sep 2009 at 3:23

GoogleCodeExporter commented 9 years ago
I was able to reproduce this behavior. According to the documentation for the
getAttributes method of the SnippetsEntry object
(http://code.google.com/apis/gdata/jsdoc/1.10/index.html) the API returns a Map 
from
attribute name to the Attribute object.

However when there are multiple instances of the attribute, as with 
"image_link", the
Map value will be an Attribute array rather than an Attribute object, which 
leads to
the ClassCastException.

If you need an immediate workaround you can pass the result of get() through the
following native function:
private native JsArray<Attribute> expand(JavaScriptObject jso) /*-{
    if (jso.length) return jso;
    else return [jso];
}-*/;

For example:
JsArray<Attribute> all = expand(entry.getAttributes().get("image_link"));
JsArray<Attribute> all = expand(entry.getAttributes().get("price"));

This would transform the output of get() into an Attribute array, even for
single-instance attributes, such as "price" here.

Original comment by bobbysoa...@gmail.com on 21 Sep 2009 at 8:29

GoogleCodeExporter commented 9 years ago

Original comment by bobbysoa...@gmail.com on 21 Sep 2009 at 8:29

GoogleCodeExporter commented 9 years ago
Fixed in version 2.0.1.

Original comment by bobbysoa...@gmail.com on 1 Nov 2009 at 8:06