I have got one very simple java spring boot + swagger project.
Only for test purposes I've created two mapping classes: Names.java and NamesContainer.java
public class Names {
@XmlAttribute(name="ref")
@ApiModelProperty(notes = "The auto-generated version of the product...")
private String key;
@XmlValue
@ApiModelProperty(notes = "The auto-generated version of the product...")
private String name;....-> rest of the class(Default constuctor and getters and setters)
...........
@XmlRootElement(name="root")
public class NamesContainer {
@XmlElement(name="listNames")
@ApiModelProperty(notes = "The auto-generated version of the product")
private List<Names> listNames;....-> rest of the class(Default constuctor and getters and setters)
For response I use one @Get method:
@RequestMapping(method = RequestMethod.GET, value = "/api/javainuse")
@ApiOperation(value = "Get a scheduled process by id.",notes = "This is note ;)",response = NamesContainer.class,code = HttpURLConnection.HTTP_OK, produces="text/html")
@ApiResponses(value = {@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "set in case of success. Returns the requested scheduled process", response = NamesContainer.class)})
public NamesContainer sayHello() {
Map<String, String> mapNames = new HashMap<String, String>();
mapNames.put("Name1", "Docnho");
mapNames.put("Name2", "Silvia");
mapNames.put("Name3", "Pepa");
mapNames.put("Name4", "Mima");
mapNames.put("Name5", "Mohamed");
List<Names> listNames = new ArrayList<Names>();
for(Map.Entry<String, String> entryName : mapNames.entrySet())
{
listNames.add(new Names(entryName.getKey(), entryName.getValue()));
}
NamesContainer container = new NamesContainer(listNames);
return container;
}
If I use produces="application/json" or produces="application/xml", the result is as expected:
But if I try to use produces="text/html"
The response is not as expected:
and Response Body is;
<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Fri Mar 15 18:43:55 EET 2019</div><div>There was an unexpected error (type=Not Acceptable, status=406).</div><div>Could not find acceptable representation</div></body></html>
The question is is it possible to map my existing object NamesContainer.java in way in which I can generate HTML response and how to do that?