使用JAXB和Jersey包装XML响应(Wrap XML response with JAXB and Jersey)
我使用Jersey来实现我的REST API,我有以下服务:
@Path("discoverytopology") public class DiscoveryTopology { @GET @Produces("application/xml") public List<Definition> getDefinitionList() { List<Definition> definitions = db.getDefinitions(); return definitions; } }
Definition
类由XML注释注释,XML中的响应包含许多定义,如:<defition body> <defition body> ....
但我想要这样的东西,我需要一个XML的每个定义的ID,就像:
<DefinitionList> <definition id=1> <definition body> </definition> <definition id=2> <definition body> </definition> ............ </DefinitionsList>
我怎么能这样做?
I use Jersey to implement my REST API and I have the following service:
@Path("discoverytopology") public class DiscoveryTopology { @GET @Produces("application/xml") public List<Definition> getDefinitionList() { List<Definition> definitions = db.getDefinitions(); return definitions; } }
The
Definition
class is annotated by XML annotation and the response in XML contains many definitions like:<defition body> <defition body> ....
But I want something like this, I need an ID for each definition in XML, just like:
<DefinitionList> <definition id=1> <definition body> </definition> <definition id=2> <definition body> </definition> ............ </DefinitionsList>
How I can do it?
原文:https://stackoverflow.com/questions/33803638
更新时间:2024-02-13 09:02
最满意答案
尝试这个:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); try { customTabsIntent.launchUrl(this, Uri.parse("https://docs.google.com/viewerng/viewer?url=" +pdflink)); } catch (ActivityNotFoundException e) { // display message to user }
Try this:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); try { customTabsIntent.launchUrl(this, Uri.parse("https://docs.google.com/viewerng/viewer?url=" +pdflink)); } catch (ActivityNotFoundException e) { // display message to user }
相关问答
更多-
检测到您活动中的网页时,请尝试将活动放在最顶层(而不是背景中的Chrome自定义标签),如下所示: // Launch activity again Intent intent = new Intent(this, A.class); // Setting CLEAR_TOP ensures that all other activities on top of A will be finished // and setting SINGLE_TOP ensures that a new instance ...
-
尝试动态创建链接并调用其click方法。 function openTab(url) { var a = document.createElement('a'); a.href = url; a.target='_blank'; a.click(); } 然后你可以像这样调用这个函数: openTab('http://google.com'); 更新 上一个示例在默认浏览器中打开链接(可能是除Chrome之外的其他内容) 如果要强制链接在chrome中打开,请使 ...
-
这用于设置辅助工具栏的颜色,也称为底部工具栏(请参阅CustomTabsIntent.Builder#addToolbarItem )。 从API级别24.1.0开始 ,添加项目以将项目添加到底部工具栏的方法已被弃用,以支持使用RemoteViews ,您可以在其中定义应用中的样式。 检查CustomTabsIntent.Builder#setSecondaryToolbarViews以获取更多信息。 还有一个关于如何在Github示例中使用它的例子 。 This is used to set the co ...
-
问题是我的活动有启动模式“singleInstance”。 更改为“singleTask”或者没有在AndroidManifest中设置launchMode解决了这个问题。 不知道为什么会这样。 如果您知道原因,我很乐意将您的解释标记为解决方案。 The problem is that my activity had the launch mode "singleInstance". Changing to "singleTask" or not having a launchMode set in the ...
-
您可以跟踪活动A上的布尔变量上打开自定义选项卡。 private boolean mCustomTabsOpened = false; public void launchCustomTabs(String url) { mCustomTabsOpened = true; new CustomTabs.Builder().build().launchUrl(this, Uri.parse(url)); } 然后,使用活动A的onResume()启动活动B. public void onRes ...
-
编辑:这实际上可能是由于我们在Android的最新版本的Branch SDK中出现的错误。 你能确认你使用的是v2.4.4或更高版本吗? 来自Branch.io的Alex:很高兴听到你发现Branch链接很有用! Branch实际上并不支持应用内部深层链接,这听起来就像你想要实现的那样。 您最好使用标准机制在应用程序内的活动之间移动,并依靠Branch来处理来自外部的用户。 EDIT: this actually might be due to a bug we had in a recent versio ...
-
尝试这个: CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); try { customTabsIntent.launchUrl(this, Uri.parse("https://docs.google.com/viewerng/viewer?url=" +pdflink)); } catch (ActivityNot ...
-
最简洁的答案是不。” 谷歌确实在他们的页面上提到了一些讨论移动模拟器的限制 ,但他们似乎不承认所有的错误/问题。 Mobile1st在本文中简要介绍了它的局限性,他们提到模拟器在以下方面受到限制: 渲染引擎 - 这是浏览器用来解释HTML / CSS并创建我们在浏览器中看到的代码。 这是一个相当大的缺点。 移动模拟器是一个方便的工具,我使用它,但我从不依赖它。 我总是进去在实际设备上测试我的设计。 几乎总是存在差异,而且差异往往非常显着。 The short answer is "no." Google d ...
-
我不确定你能不能这样做。 您可以尝试启动CustomTabIntent for result并等待它完成,然后根据您启动它的requestCode从onActivityResult()启动它。 private void openUrlForResult(CustomTabsIntent customTabsIntent, String url, int requestCode){ customTabsIntent.intent.setData(Uri.parse(url)); ...
-
从自定义扩展程序访问“Chrome开发工具移动模拟器”(Access 'Chrome dev-tool mobile emulator' from custom extension)[2022-03-14]
您必须通过devtools协议使用setDeviceMetricsOverride 。 您可以在chrome.debugger chrome扩展API中访问它。 您将使用该方法,可能还有其他方法来设置UA等。 我的chrome扩展程序的示例代码 。 示例(来自@onsy ): chrome.debugger.sendCommand(debuggeeId, "Network.enable", {}, onResponse); chrome.debugger.sendCommand(debuggeeId, ...