使用REST端点返回字符串

Iwo*_*ski 3 java rest angularjs

在你减去这个问题之前,你应该知道我搜索了解决方案而没有找到它.

我想通过rest端点返回String:

    @GET
    @Path("/getMyString")
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getId() {
    String s = "this is my string";
    (...)
    return Response.ok(s).build();
    }
Run Code Online (Sandbox Code Playgroud)

但是在视图中我收到了char数组(结果是firebug):

Resource { 0="t", 1="h", 2="i", more...}
Run Code Online (Sandbox Code Playgroud)

在前面我使用角度资源,如:

blablaResources.factory('AngularApp', [ '$resource', function($resource) {
    return $resource(contextPath + '/.rest/v1/someService', {}, {
        (... other methods ...)
        getString : {
            method : 'GET',
            url : contextPath + '/.rest/v1/someService/getMyString'
        }
    });
} ]);
Run Code Online (Sandbox Code Playgroud)

是否有任何String或注释的包装类来发送它:

Resource { value = "this is my string" }
Run Code Online (Sandbox Code Playgroud)

或者只是正常

"this is my string"
Run Code Online (Sandbox Code Playgroud)

感谢任何建设性的回应:)

Pet*_*Mmm 5

尝试使用

@Produces({ MediaType.TEXT_PLAIN })
Run Code Online (Sandbox Code Playgroud)