1

I want to split a very large string into multiple lines. When I use next line characters, those characters are displayed in Swagger UI without having multiple lines.

Code is as below:

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


@Path("test")
@Api(tags = {"Testing"})
public class TestingService {

@Context
private HttpServletRequest request;

@GET
@Path("testing")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Testing",
response = String.class)    
public String getString(
         throws Exception {
    return "abcdef,fghijk";
}
}

Input is:

abcdef,fghijk
Current Output:
{

  "messages": "abcdef,fghijk"
}

Expected Output:    
{

  "messages": "abcdef,
              fghijk"
}

I have tried \n, \\n, \\\n and \r\n.

Note: I am using Jersey Framework for this REST API & Swagger for UI.

Thanks a lot in advance for the help.

Rohit Kumar
  • 103
  • 2
  • 17

1 Answers1

0

Workaround : (a) split the string on some basis (b) create a list of object where object stores the split string. (c)Send the list to UI as response.

Output will be as below:

{

  "messages_list": [
                    {"message": "abcdef"},
                    {"message": "fghijk"}
                   ]
}

Note: This was not the actual requirement. This is just workaround to display long & different messages in different lines.

Rohit Kumar
  • 103
  • 2
  • 17