【问题标题】:Map<String,String> Key Value on PostmanPostman 上的 Map<String,String> 键值
【发布时间】:2020-04-16 04:08:56
【问题描述】:

我目前正在构建一个控制器,它将接受带有 Map 的参数,由于 Multipart File,我需要通过表单数据传递它。我无法通过邮递员传递地图,它一直给我这个错误

"Failed to convert property value of type java.lang.String to required type java.util.Map for property variables; nested exception is java.lang.IllegalStateException: Cannot convert value of type java.lang.String to required type java.util.Map for property variables: no matching editors or conversion strategy found"

这是我目前传递给 PostMan 的内容

variables

价值

variables : {"abc": "123"}

【问题讨论】:

    标签: java api controller postman


    【解决方案1】:

    您需要反序列化该字符串。 也许你想看看像 GSON 这样的东西来将 JSON 字符串转换成你的 Java Map&lt;String, String&gt; https://github.com/google/gson

    应该是这样的:

        String someJSONMap = "{\"abc\":\"123\"}";
        Gson gson = new Gson();
        Type type = new TypeToken<HashMap<String, String>>(){}.getType();
        Map<String,String> result = gson.fromJson(someJSONMap, type);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-01
      相关资源
      最近更新 更多