以下を含む RESTful Web サービスをセットアップしました。
    @GET
@Path("{from}/{to}")
@Produces({"application/xml", "application/json"})
public List<Story> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
    return super.findRange(new int[]{from, to});
}
データベース内のすべての Story オブジェクトのリストを返します。私もこれを持っています:
    @GET
@Path("{id}")
@Produces({"application/xml", "application/json"})
public Story find(@PathParam("id") Short id) {
    return super.find(id);
}
パスの末尾に「/{id}」を追加すると、単一の Story オブジェクトが返されます。これらは両方ともサーバー上で正常に動作し、期待される結果を返します。クライアント側では、後者の方法は次のコードを使用して完全に機能します。
HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(url);
        httpget.addHeader("accept", "application/json");
        HttpResponse response;
        JSONObject object = new JSONObject();
        String resprint = new String();
        try {
            response = httpclient.execute(httpget);
            // Get the response entity
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                // get entity contents and convert it to string
                InputStream instream = entity.getContent();
                String result= convertStreamToString(instream);
                resprint = result;
                // construct a JSON object with result
                object=new JSONObject(result);
                // Closing the input stream will trigger connection release
                instream.close();
            }
        } 
        catch (ClientProtocolException e) {System.out.println("CPE"); e.printStackTrace();} 
        catch (IOException e) {System.out.println("IOE"); e.printStackTrace();} 
        catch (JSONException e) { System.out.println("JSONe"); e.printStackTrace();}
        System.out.println("FUCKYEAHBG: " + resprint);
        return object;
    }
}
私の問題は、JSON Story オブジェクトのリストを返す必要がある最初のメソッドでこの同じコードを使用しようとすると、JSON 例外が発生することです: Type Mismatch.
単一のオブジェクトではなく、json オブジェクトの配列を受け入れるようにこのコードを変更するにはどうすればよいですか?