返回一个带有1个对象和2个其他值的自定义json
我和Jackson一起使用Spring,我需要返回类似返回一个带有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
{
"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);
测试。放置(“用户”,用户);
测试。放置(“自定义”,自定义);
回归试验;
哦,对不起,我拼错了标题。它不是两个对象,而是一个对象和两个不同的布尔值。嗯,我想这仍然有效,谢谢!