javaspringspring-booticalendarical4j

No line separation when sending an iCalendar to web page. Java


I am trying to send an iCalendar to webpage but when I send it there is no line separation and it is not considered as correct iCalendar format. If I send iCalendar format its just JSON format. And if its calendar.toString() there is no line separation. How can I send it in correct format?

Calendar calendar = iCalendarService.getCalendar();
System.out.println(calendar); //Correct format in console
return ResponseEntity.ok(calendar.toString()); //No line separation
//return ResponseEntity.ok(calendar); // Json

Solution

  • If your code is defined at a Controller method level, try to set the media type to text/calendar:

    @RequestMapping(
        method = RequestMethod.GET,
        value = "/your/path",
        produces = "text/calendar"
    )
    

    Alternatively, you can try the following return line:

    return ResponseEntity.ok().contentType(new MediaType("text", "calendar")).body(calendar.toString());