@Override
    public ResponseEntity<String> build(final Ticket ticketGrantingTicket, final HttpServletRequest request) throws Throwable {
        var tokenParam = request.getParameter(TokenConstants.PARAMETER_NAME_TOKEN);
        if (StringUtils.isBlank(tokenParam)) {
            tokenParam = request.getHeader(TokenConstants.PARAMETER_NAME_TOKEN);
        }
        if (StringUtils.isBlank(tokenParam) || !BooleanUtils.toBoolean(tokenParam)) {
            LOGGER.debug("The request indicates that ticket-granting ticket should not be created as a JWT");
            return super.build(ticketGrantingTicket, request);
        }
        val claims = (Map) request.getParameterMap()
            .entrySet()
            .stream()
            .filter(entry -> !IGNORED_PARAMS.contains(entry.getKey()))
            .map(entry -> Pair.of(entry.getKey(), CollectionUtils.toCollection(entry.getValue(), ArrayList.class)))
            .collect(Collectors.toMap(Pair::getKey, Pair::getValue));
        val jwt = tokenTicketBuilder.build((AuthenticationAwareTicket) ticketGrantingTicket, claims);
        LOGGER.debug("Generated JWT [{}]", jwt);

        val headers = new HttpHeaders();
        headers.setContentType(MediaType.TEXT_PLAIN);
        val entity = new ResponseEntity<>(jwt, headers, HttpStatus.CREATED);
        LOGGER.debug("Created response entity [{}]", entity);
        return entity;
    }
This is {@link JwtTicketGrantingTicketResourceEntityResponseFactory}.

@author Misagh Moayyed
@since 5.2.0
support/cas-server-support-rest-tokens/src/main/java/org/apereo/cas/tokens/JwtTicketGrantingTicketResourceEntityResponseFactory.java