返回AWS lambda功能的缩进缩进的JSON



我在java中设置了我的lambda函数:

public class Handler implements RequestHandler <Request, List <Response>>
{
    public List <Response> handleRequest (Request request, Context context)
    {                       
        List <Response> userList = new ArrayList <Response>();
        for (int i = 0; i < values.length; i++)
        {
            Response user = new Response();
            user.setUserID (Integer.parseInt (values[i][0]));
            user.setUserTypeName (values[i][1]);
            user.setUserEmail (values[i][2]);
            user.setUserFirstName (values[i][3]);
            user.setUserLastName (values[i][4]);
            user.setUserRole (values[i][5]);
            user.setActiveYN (values[i][6]);
            userList.add (user);
        }
        return userList;
    }
}

AWS API Gateway做了它的事情,并且它返回了一系列虚拟对象,就可以了:

[{"userID":1,"userTypeName":"Adminstrator","userEmail":"joesmiley@gmail.com","userFirstName":"Joe","userLastName":"Smiley","userRole":"n/a","activeYN":"y"},
{"userID":2,"userTypeName":"Manager","userEmail":"sandyjones@gmail.com","userFirstName":"Sandy","userLastName":"Jones","userRole":"n/a","activeYN":"y"},
{"userID":3,"userTypeName":"Manager","userEmail":"jasonsmith@gmail.com","userFirstName":"Jason","userLastName":"Smith","userRole":"n/a","activeYN":"y"},
{"userID":4,"userTypeName":"Manager","userEmail":"neoanderson@gmail.com","userFirstName":"Neo","userLastName":"Anderson","userRole":"n/a","activeYN":"y"}]

问题是我的整洁症状,因此此返回服务需要空格!据我所知,我的Java方法只能控制信息,而不能控制介绍。这是可能的微调吗?

编辑

尝试返回jsonarray;相同的结果。

JSONArray indentedReturn = new JSONArray();
indentedReturn.addAll (userList);
return indentedReturn;

如果您确实需要凹痕,则应该在客户端上显示JSON,而不是通过网络发送Whitespaces和Line Brake。如果出于任何选择,您都可以将对象格式化为lambda函数内的JSON字符串并返回字符串而不是列表。

相关内容

  • 没有找到相关文章

最新更新