nourelhoudabenahmed / facebook-java-api

Automatically exported from code.google.com/p/facebook-java-api
0 stars 0 forks source link

stream.publish property order is not retained #266

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Call stream_publish() with an Attachment object containing properties that 
were added in a 
specific order for display.

What is the expected output? What do you see instead?

Expected the properties to be displayed in the order that they were added to 
the 
List<AttachmentProperty> object, as per the semantics of List.  Actual output 
is random order of 
properties.

Currently, the Attachment.java class sends attachment properties as a single 
JSON object with 
name-value pairs.  I'm not exactly sure why this functions, because according 
to the (very 
sketchy) Facebook API docs, we should be sending either strings or objects in a 
specific format:

   An array of key/value pairs that provide more information about the post.
  The properties array can contain plain text and links only.  To include a link,
  the value of the property should be a dictionary with 'text' and 'href' attributes.

At first, I modified the Attachment.java class to send an array of strings for 
properties:

  properties: [ "name1: value1", "name2: value2", "name3: value3" ]

This results in a stream post with the following display:

  name1: value1
  1: name2: value2
  2: name3: value3

The "1:" and "2:" are added by Facebook.  To avoid getting the array indices 
added to my 
properties, I have to send a single JSON object:

  properties: { "name1" : "value1", "name2" : "value2", "name3" : "value3" }

Attachments.java builds up the properties value as an org.json.JSONObject.  
Unfortunately, this 
class strictly follows the JSON spec, which says that an object's properties 
are unordered.  So 
we've gone from an ordered Java list to an unordered map.

The solution is to specify a Map subclass for JSONObject to use which preserves 
the order of 
entry.  Unfortunately, JSONObject.toString() still mucks with the property 
order, so you have to 
override the sortedKeys() method as well:

        JSONObject jsonProperties = new JSONObject(new LinkedHashMap()) {
            public Iterator sortedKeys() {
                return this.keys();
            }
        };

With this change, the properties retain the order they are given in the 
List<AttachmentProperty> 
object.

What version of the product are you using? On what operating system?

3.0.2-SNAPSHOT, CentOS 5.3, JDK 1.6.0

Please provide any additional information below.

Original issue reported on code.google.com by paule...@gmail.com on 14 Nov 2009 at 1:13

Attachments:

GoogleCodeExporter commented 8 years ago
any chance on getting the patch into 3.0.2-SNAPSHOT?

Original comment by paule...@gmail.com on 24 Nov 2009 at 7:03

GoogleCodeExporter commented 8 years ago
updated patch for rev 946.

Original comment by paule...@gmail.com on 16 Dec 2009 at 10:57

Attachments:

GoogleCodeExporter commented 8 years ago
patch has been applied.. waiting for build

Original comment by fern...@gmail.com on 17 Dec 2009 at 12:04

GoogleCodeExporter commented 8 years ago
Has this bug been fixed in the latest release.I am also facing the same issue 
of 
unordered attachment properties

Original comment by udayo...@gmail.com on 6 May 2010 at 2:29

GoogleCodeExporter commented 8 years ago
Will there be a 3.0.3 release?

Original comment by likwong...@gmail.com on 11 Aug 2010 at 2:32