如何使用地图<;对象,双>;在使用Java的端点框架中?

如何使用地图<;对象,双>;在使用Java的端点框架中?,java,google-app-engine,serialization,gson,google-cloud-endpoints,Java,Google App Engine,Serialization,Gson,Google Cloud Endpoints,我有一个类GChemin,它包含一个Map属性。GR2包含四个double属性。生成客户机libs时,映射将变成JsonMap。我的问题是如何处理这个问题 我试图用Gson格式化的JSON GR2作为键填充JsonMap,但端点无法处理它。我得到了这个错误: com.fasterxml.jackson.databind.JsonMappingException:找不到类型[simple type,class GR2]的(映射)键反序列化器 GR2级: public class GR2 imple

我有一个类
GChemin
,它包含一个
Map
属性。GR2包含四个
double
属性。生成客户机libs时,映射将变成
JsonMap
。我的问题是如何处理这个问题

我试图用Gson格式化的JSON GR2作为键填充JsonMap,但端点无法处理它。我得到了这个错误:

com.fasterxml.jackson.databind.JsonMappingException:找不到类型[simple type,class GR2]的(映射)键反序列化器

GR2级

public class GR2 implements Serializable
    {

    public GR2(double x, double y)
        {
        this.x = x;
        this.y = y;
        }

    public GR2()
        {
        }

    @Override
    public String toString()
        {
        StringBuilder builder = new StringBuilder();
        builder.append("GR2 [x=");
        builder.append(this.x);
        builder.append(", y=");
        builder.append(this.y);
        builder.append("]");
        return builder.toString();
        }


    public double getX()
        {
        return this.x;
        }

    public double getY()
        {
        return this.y;
        }

    public void setX(double x)
        {
        this.x = x;
        }

    public void setY(double y)
        {
        this.y = y;
        }

    private double x;
    private double y;
    }
将映射转换为JsonMap
toG()
方法只需从
R2
创建一个
GR2
对象(可序列化):

Api方法(gChemin包含属性
map


你希望你的对象如何被序列化?@saiyr是的,我希望!但是序列化是由端点框架完成的,通常我对它没有任何问题。它可以毫无问题地序列化一个列表。我的意思是你能展示一个你期望的JSON示例吗?@saiyr实际上我不期望JSON有任何特定的格式,我只希望我的对象(带有映射)被传输到端点。但是我必须手动填充JsonMap,对吗?我真的不知道怎么做,但endpoints框架需要一些特定的东西。如果无法猜测正确的格式,那么什么是好的解决方法?这修复了当参数是类似数组的结构时路径参数的反序列化。我是从一个电话亭接过来的。你会认为这是同样的问题,但现在的地图结构?
public static JsonMap toJsonMap(Map<R2, Double> map)
    {
    JsonMap jsonMap = new JsonMap();
    map.entrySet().forEach(entry -> jsonMap.put(toJSON(
                           toG(entry.getKey())), 
                           entry.getValue()));
    return jsonMap;
    }
public static String toJSON(GR2 gr2)
    {
    return new Gson().toJson(gr2);
    }
@ApiMethod(name = "save", httpMethod = HttpMethod.POST)
public GBoolean save(GChemin gChemin)
    {
    // Work with gChemin
    }