Q: CORS response when using objectWritter as written type - Jersey I am using Jersey service and sending a json response from a service call. Now my service will be used from cross domain as well. so i want to implement CORS in my code. I saw few examples in internet but all are returning response object. But in my code i am returning as ObjectWritter. in this case how to make this as CORS.
My code as below
@GET
      @Produces(MediaType.APPLICATION_JSON)
      @Path("/sampleUrl/{pageNumber}")
      public String fetchAlertRecords(@PathParam("pageNumber") int pageNumber) throws Exception {
          List<CustomVO> list = new ArrayList<CustomVO>();
          //do somethimg to insert values to list
          ObjectWriter writer = null;
          ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_NULL);
        FilterProvider filters = new SimpleFilterProvider()  
          .addFilter(filterClass,SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames));  
        writer = mapper.writer(filters);
        return writer.writeValueAsString(list);
   }


A: CORS is about request/response headers, what you return (btw you return String and not ObjectWriter) is a response body. So use CORS as you have seen it in examples. May be this link will help https://spring.io/guides/gs/rest-service-cors/
