首页 \ 问答 \ 使用JAXB和Jersey包装XML响应(Wrap XML response with JAXB and Jersey)

使用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)); ...
  • 您必须通过devtools协议使用setDeviceMetricsOverride 。 您可以在chrome.debugger chrome扩展API中访问它。 您将使用该方法,可能还有其他方法来设置UA等。 我的chrome扩展程序的示例代码 。 示例(来自@onsy ): chrome.debugger.sendCommand(debuggeeId, "Network.enable", {}, onResponse); chrome.debugger.sendCommand(debuggeeId, ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。