GSON not returning key name, only value (Java)
<p>I'm trying to format some String data to JSON using the GSON api, as shown in my returnJson() method:</p>

<pre><code>import com.google.gson.*;
import com.google.gson.annotations.SerializedName;

public class HUKD {
    @SerializedName("title")
    public String title;
    @SerializedName("Deal URL")    
    public String dealUrl;
    @SerializedName("Product URL")    
    public String productUrl;
    @SerializedName("Image URL")        
    public String imgUrl;
    @SerializedName("Description")        
    public String description; 
    @SerializedName("Temperature")        
    public String temperature;
    @SerializedName("EAN")
    public String ean;
    @SerializedName("Price")
    public String price;
    @SerializedName("Amazon Price")
    public String amazonPrice;
    @SerializedName("Price Difference")
    public String priceDifference;
    @SerializedName("Amazon URL")
    public String amazonUrl;

    public HUKD(String title, String dealUrl, String productUrl, String imgUrl, String description, String temperature, String ean, String price, String amazonPrice, String priceDifference, String amazonUrl) {
        this.title = title;
        this.dealUrl = dealUrl;
        this.productUrl = productUrl;
        this.imgUrl = imgUrl;
        this.description = description;
        this.temperature = temperature;
        this.ean = ean;
        this.price = price;
        this.amazonPrice = amazonPrice;
        this.priceDifference = priceDifference;
        this.amazonUrl = amazonUrl;
    }

public String returnJson(){
    System.out.println("********TESTING OBJECTS*************");
    String[] jsonBuilder = new String []{title, dealUrl, productUrl, imgUrl, description, temperature, ean, price, amazonPrice, priceDifference, amazonUrl};
    Gson gson = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
    String json = gson.toJson(jsonBuilder );
    return json;
}
</code></pre>

<p>However, GSON will only return the value, not the key:</p>

<pre><code>[
  "Philips shm3560/10 on ear headphones Â£8.99 from Argos",
  "http://www.hotukdeals.com/deals/philips-shm3560-10-headphones-8-99-from-argos-2390246?aui\u003d1063",
  "http://www.hotukdeals.com/visit?m\u003d5\u0026q\u003d2390246",
  "http://static.hotukdeals.com/images/threads/2390246_1.jpg",
  "Argos cat no- 108/7390\nhttp://www.argos.co.uk/webapp/wcs/stores/servlet/SearchMobile?storeId\u003d10151\u0026catalogId\u003d25051\u0026langId\u003d110\u0026searchTerm\u003d108%2F7390",
  "171°",
  "8712581626211",
  "£8.99",
  "£12.59",
  "Argos is cheaper than Amazon by £3.60",
  "http://www.amazon.co.uk/Philips-SHM3560-10-Pc-headset-Shm3560/dp/B008FSE6EU%3FSubscriptionId%3DAKIAILN2TPM667MBMJAQ%26tag%3Dgithubcomthis-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB008FSE6EU"
]
</code></pre>

<p>I've tried to get around this by adding the SerializedName annotation as suggested in the "JSON Field Naming Support" section of the API documentation <a href="https://sites.google.com/site/gson/gson-user-guide" rel="nofollow">here</a>, but I'm still not having any luck. Ideally, I'd like the JSON formatted like so:</p>

<pre><code>"title":"Philips shm3560/10 on ear headphones Â£8.99 from Argos"
</code></pre>

<p>(and so on...), i.e. with the key name printed as specified in the @SerializedName annotation in the field declaration. </p>

<p>Thanks!</p>