Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.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
将带有一个元素的Java ArrayList转换为JSON对象时出现问题_Java_Web Services_Json - Fatal编程技术网

将带有一个元素的Java ArrayList转换为JSON对象时出现问题

将带有一个元素的Java ArrayList转换为JSON对象时出现问题,java,web-services,json,Java,Web Services,Json,我开发了RESTWeb服务来获取JSON对象列表。当存在多个对象时,rest web服务将返回正确的JSON数组。但如果只有一个对象返回Rest web服务,则不会返回JSON数组。我一直想得到JSON数组 我的休息服务方式 @GET @Produces("application/json") @Path("/chekinList") public List<LocationReguest> getChekinList(@QueryParam("childID") String us

我开发了RESTWeb服务来获取JSON对象列表。当存在多个对象时,rest web服务将返回正确的JSON数组。但如果只有一个对象返回Rest web服务,则不会返回JSON数组。我一直想得到JSON数组

我的休息服务方式

@GET
@Produces("application/json")
@Path("/chekinList")
public List<LocationReguest> getChekinList(@QueryParam("childID") String userName, @QueryParam("appkey") String appkey, @QueryParam("appPassword") String appPassword) {
    LocationController locationController = new LocationController();
    List<LocationReguest> locreqlist = locationController.getChekinList(userName);
    //TODO return proper representation object
    return locreqlist;
}
@GET
@生成(“应用程序/json”)
@路径(“/chekinList”)
公共列表getChekinList(@QueryParam(“childID”)字符串用户名,@QueryParam(“appkey”)字符串appkey,@QueryParam(“appPassword”)字符串appPassword){
LocationController LocationController=新的LocationController();
List locreqlist=locationController.getChekinList(用户名);
//TODO返回正确的表示对象
返回LOCREQ列表;
}
有一个对象时返回JSON对象 {“childRequest”:{“childName”:“test123Child”,“childUserName”:“add”}

JSON对象数组在有更多对象时返回

{“childRequest”:[{“childName”:“Child” 一个“,“childUserName”:“chlid1”},{“childName”:“abayakoon”,“childUserName”:“abey”}]}


请帮助我解决此问题

请参阅解决方法

请参阅解决方法

您使用什么类/库转换为JSON?您使用什么类/库转换为JSON?我已将抛弃1.1库替换为抛弃1.2。但这并不能解决我的问题。解决方法是使用自定义的
ContextResolver
,如所提供的链接中所述。我已将抛弃1.1库替换为抛弃1.2。但这并不能解决我的问题。解决方法是使用自定义的
ContextResolver
,如提供的链接中所述