杰克逊将List <string>转换为String

时间:2016-04-15 16:05:00

标签: java input jackson

我想使用List<String> requestBody

将以下String变成Jackson
[{"userId":"GZiLXipGgoZeZBCy","displayName":"759383","role":"FATHER"}, 
 {"userId":"HKtpZCfBlfMEiYaH","displayName":"291848","role":"SON"}]

所以我使用Jackson实现了这个:

["{\"userId\":\"GZiLXipGgoZeZBCy\",\"displayName\":\"759383\",\"role\":\"FATHER\"}",
 "{\"userId\":\"HKtpZCfBlfMEiYaH\",\"displayName\":\"291848\",\"role\":\"SON\"}"]

我的代码是:

    final OutputStream out = new ByteArrayOutputStream();
    final ObjectMapper mapper = new ObjectMapper();
    mapper.writeValue(out, requestBody);

    final String data = out.toString();

有人可以帮我修复String吗?

(我的request需要String而不是List<String>

由于

0 个答案:

没有答案