Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回一个带有1个对象和2个其他值的自定义json_Json_Spring_Jackson - Fatal编程技术网

返回一个带有1个对象和2个其他值的自定义json

返回一个带有1个对象和2个其他值的自定义json,json,spring,jackson,Json,Spring,Jackson,我和Jackson一起使用Spring,我需要返回类似 { "user": { "username":"myusername", "mail":"mymail" }, "custom": { "hasVoted":"true", "hasCommented":"false" } } 直到今天,我才发回一个转换成jackson的用户对象,但现在我需要添加一个自定义参数。我该怎么做?谢谢。Map test=newhashmap(); Map<S

我和Jackson一起使用Spring,我需要返回类似

{
"user": {
    "username":"myusername",
    "mail":"mymail"
    },
"custom": {
    "hasVoted":"true",
    "hasCommented":"false"
    }
}
直到今天,我才发回一个转换成jackson的用户对象,但现在我需要添加一个自定义参数。我该怎么做?谢谢。

Map test=newhashmap();
Map<String, Object> test = new HashMap<String, Object>();
    Map<String, Boolean> custom = new HashMap<>();
    custom.put("hasVoted", true);
    custom.put("hasCommented", false);
    test.put("user", User);
    test.put("custom", custom);
    return test;
Map custom=newhashmap(); custom.put(“hasvided”,true); custom.put(“hasCommented”,false); 测试。放置(“用户”,用户); 测试。放置(“自定义”,自定义); 回归试验;
哦,对不起,我拼错了标题。它不是两个对象,而是一个对象和两个不同的布尔值。嗯,我想这仍然有效,谢谢!