继上一个问题之后,我可以在自定义属性部分返回组列表,但是我想知道我需要做什么才能以标准 JSON 结构返回它们。
如果我发回一个 Java 列表
HashMap<String, Object> customAttributes = new HashMap<String, Object>();
customAttributes.put("AuthenticationDate", new Date());
List<String> groups = new ArrayList<String>();
groups.add("Users");
groups.add("Managers");
customAttributes.put("Groups", groups);
UserIdentity identity = new UserIdentity(loginModule, USERNAME, "Fred Flintstone", null, customAttributes, PASSWORD);
然后客户端收到
{"Groups":"[Users, Managers]","AuthenticationDate":"Tue Nov 26 12:07:37 EST 2013"}
如果我在 hashMap 中添加组
List<Map<String, Object>> groups = new ArrayList<Map<String, Object>>();
HashMap<String, Object> groupMap1 = new HashMap<String, Object>();
groupMap1.put("id", "Users");
groups.add(groupMap1);
HashMap<String, Object> groupMap2 = new HashMap<String, Object>();
groupMap2.put("id", "Managers");
groups.add(groupMap2);
customAttributes.put("Groups", groups);
UserIdentity identity = new UserIdentity(loginModule, USERNAME, "Fred Flintstone", null, customAttributes, PASSWORD);
我在客户端收到以下响应
"attributes":{"Groups":"[{id=Users}, {id=Managers}]","AuthenticationDate":"Tue Nov 26 12:13:40 EST 2013"}
我真正想要的是这样的
"attributes":{"Groups":[{"id" : "Users"}, {"id" :"Managers"}],"AuthenticationDate":"Tue Nov 26 12:13:40 EST 2013"}