kidager / google-gson

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

Support new Guava collections by default #526

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create Guava collection as a member element of a class. Example:

import java.util.Collection;
import java.util.Map;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class GsonExample {
    private final Multimap<String, String> map = HashMultimap.create();
    private final Map<String, Collection<String>> asMap;
    public GsonExample() {
        map.put("a", "a");
        map.put("a", "b");
        map.put("b", "b");
        asMap = map.asMap();
    }
    public static void main(String[] args) {
        GsonExample ex = new GsonExample();
        Gson g = new GsonBuilder().setPrettyPrinting().create();
        System.out.println(g.toJson(ex));
    }
}

What is the expected output? What do you see instead?
Expected:
{
  "map": {
    "b": [
      "b"
    ],
    "a": [
      "b",
      "a"
    ]
  },
  "asMap": {
    "b": [
      "b"
    ],
    "a": [
      "b",
      "a"
    ]
  }
}

Actual:
{
  "map": {},
  "asMap": {
    "b": [
      "b"
    ],
    "a": [
      "b",
      "a"
    ]
  }
}

What version of the product are you using? On what operating system?
I am using Gson 2.2.4 and Guava 14.0.1 on Windows 7 x64, Java 7u25.

Please provide any additional information below.
This is a feature enhancement, not a bug. Thanks!

Original issue reported on code.google.com by martin.j...@gmail.com on 24 Jun 2013 at 3:33

GoogleCodeExporter commented 9 years ago
Gson will not add a dependency to Guava. 
Feel free to provide Guava type adapters in 
https://github.com/google-gson/typeadapters or any other locations.

Original comment by inder123 on 12 Nov 2014 at 11:40