私はPackagesResourceConfig
次のような独自のものを作成しました:
import com.sun.jersey.api.core.PackagesResourceConfig;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;
public class ResourceConfigClass extends PackagesResourceConfig {
@Override
public Map<String, MediaType> getMediaTypeMappings() {
Map<String, MediaType> map = new HashMap<String, MediaType>();
map.put("xml", MediaType.APPLICATION_XML_TYPE);
map.put("json", MediaType.APPLICATION_JSON_TYPE);
return map;
}
}
しかし、アプリを起動すると、次のようなエラーが表示されます。
パッケージの配列は null または空であってはなりません
これは、Jersey の次のソース コードに由来します。
/**
* Search for root resource classes declaring the packages as an
* array of package names.
*
* @param packages the array package names.
*/
public PackagesResourceConfig(String... packages) {
if (packages == null || packages.length == 0)
throw new IllegalArgumentException("Array of packages must not be null or empty");
init(packages.clone());
}
しかし、param を設定して web.xml にパッケージを設定しているcom.sun.jersey.config.property.packages
ので、null にはなりません。