Returning String using REST Endpoint

12,202

Try to use

@Produces({ MediaType.TEXT_PLAIN })
Share:
12,202
Iwo Kucharski
Author by

Iwo Kucharski

Java Dev

Updated on June 06, 2022

Comments

  • Iwo Kucharski
    Iwo Kucharski almost 2 years

    Before you minus this question, you should know I searched for solution and didn't find it.

    I want to return String by rest endpoint:

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

    But in view I receive char array (result in firebug):

    Resource { 0="t", 1="h", 2="i", more...}
    

    In front I use angular resource like:

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

    Is there any wrapper class for String or annotation to send it like:

    Resource { value = "this is my string" }
    

    or just normal

    "this is my string"
    

    Thanks for any constructive response :)