按照
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.wadl\nTry out %shelloworld\nHit enter to stop it...",BASE_URI,BASE_URI)); system.in.read(); httpServer.stop(); }
接下来我想启用here所述的JSON POJO支持,但问题是我想以编程方式而不是通过web.xml文件(我没有web.xml文件!)来实现.
解决方法
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); }
原文地址:https://www.jb51.cc/java/122482.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。