Я создаю новый ресурс API отдыха, у которого есть @queryParam, который может быть либо "CSV", либо "XLS".Я сделал это с помощью класса enum, а затем реализовал этот формат "@DefaultValue (" xls ") @QueryParam (FORMAT_FILTER) FormatExport" Поиск в Google Я понял, что это необходимо для реализации @InitBinder, хотя InitBinder является частью Spring, а не Jersey.Есть ли эквивалент?
//1. Enum class.
public enum FormatExport
{
json("xls"),
scv("csv");
private String label;
private FormatExport(String value)
{
this.label = value;
}
public static FormatExport fromValue(String value)
{
for(FormatExport format : values())
{
if(format.label.compareToIgnoreCase(value) == 0)
{
return format;
}
}
throw new IllegalArgumentException("Unknown value type: " + value );
}
}
//2. resource
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/elements")
public Response findElements(
@DefaultValue("json") @QueryParam(FORMAT_FILTER) FormatExport format)
{
switch (format)
{
case json:
/* Code */
case scv:
/* Code */
default:
break;
}
}
//I found this
public class QuestionCategoryConverter extends PropertyEditorSupport{
public void setAsText(final String text) throws IllegalArgumentException
{
setValue(QuestionCategory.fromValue(text));
}
}
@InitBinder
public void initBinder(final WebDataBinder webdataBinder) {
webdataBinder.registerCustomEditor(QuestionCategory.class, new
QuestionCategoryConverter());
}
//This used a spring annotation