java – 如何使用Grizzly2在Jersey中以编程方式启用POJO映射?
发布时间:2020-12-14 05:27:43 所属栏目:Java 来源:网络整理
导读:按照 here的说明我有这个代码: private static URI getBaseURI() { return UriBuilder.fromUri("http://localhost/").port(9998).build();}public static final URI BASE_URI = getBaseURI();protected static HttpServer startServer() throws IOException
按照
here的说明我有这个代码:
private static URI getBaseURI() { return UriBuilder.fromUri("http://localhost/").port(9998).build(); } public static final URI BASE_URI = getBaseURI(); protected static HttpServer startServer() throws IOException { System.out.println("Starting grizzly..."); final ResourceConfig rc = new PackagesResourceConfig("amplify.api.resources"); return GrizzlyServerFactory.createHttpServer(BASE_URI,rc); } public static void main(final String[] args) throws IOException { final HttpServer httpServer = startServer(); System.out.println(String.format("Jersey app started with WADL available at " + "%sapplication.wadlnTry out %shelloworldnHit enter to stop it...",BASE_URI,BASE_URI)); System.in.read(); httpServer.stop(); } 接下来我想启用here所述的JSON POJO支持,但问题是我想以编程方式而不是通过web.xml文件(我没有web.xml文件!)来实现. 如何修改上面的代码以启用JSON POJO映射功能? 解决方法protected static HttpServer startServer() throws IOException { System.out.println("Starting grizzly..."); final ResourceConfig rc = new PackagesResourceConfig("amplify.api.resources"); rc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,true); return GrizzlyServerFactory.createHttpServer(BASE_URI,rc); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |