从Jersey 2.9开始,可以通过声明性链接为超媒体驱动的REST API创建链接关系.
这段代码,例如:
@InjectLink(
    resource = ItemResource.class,
    style = Style.ABSOLUTE,
    bindings = @Binding(name = "id", value = "${instance.id}"),
    rel = "self"
)
@XmlJavaTypeAdapter(Link.JaxbAdapter.class)
@XmlElement(name="link")
Link self;
Run Code Online (Sandbox Code Playgroud)
......理论上预计会产生这样的JSON:
"link" : {
    "rel" : "self",
    "href" : "http://localhost/api/resource/1"
}
Run Code Online (Sandbox Code Playgroud)
但是,Jersey会生成不同的JSON,其中包含许多我不需要的属性:
"link" : {
   "rel" : "self",
   "uri" : "http://localhost/api/resource/1",
   "type": null,
   "uriBuilder" : null
}
Run Code Online (Sandbox Code Playgroud)
另请注意href,它使用的是代替uri.我查看了Jersey Link对象的实现并找到了JerseyLink.
我想使用Jersey的声明性链接,而不是推出我自己的实现.我最终使用Jackson注释只是为了忽略其他JerseyLink属性.
@JsonIgnoreProperties({ "uriBuilder", "params", "type", "rels" })
Run Code Online (Sandbox Code Playgroud)
有没有人使用与Jersey的声明性链接并且具有预期的JSON输出(例如,href而不是uri没有额外的Jersey属性)而不必使用JsonIgnoreProperties或其他黑客?
谢谢. …
我们正在使用EmberJS编写应用程序.然而,我们仍然是这个框架的新手,我们很难解决一些看似直截了当的事情.
模型非常简单,有3种模型:Queue,Task和Image.我们对所有路由使用动态URI段,这些模型的路由嵌套在以下形式:: queue_id /:task_id /:image_id.
路由配置方式如下:
App.Router.map(function() {
   this.resource('queue', {path: ':queue_id'}, function() {
      this.resource('task', {path: ':task_id'}, function() {
         this.resource('image', {path: ':image_id'});
      });
   });
}
Run Code Online (Sandbox Code Playgroud)
在HTML的某个地方,我们有这个简单的模板来迭代任务中的所有图像:
{{#each task.images}}
   <li>
      {{#view App.ThumbnailView.contentBinding="this"}}
         <img {{bindAttr src="thumbnail.url"}} />
      {{/view}}
   </li>
{{/each}}
Run Code Online (Sandbox Code Playgroud)
以下是缩略图视图的代码:
App.ThumbnailView = Ember.View.extend({
   tagName : 'a',
   click : function(e) {
       var task = //assume this value exists;
       var queue = //assume this value exists;
       var image = //assume this value exists;
       this.get('controller.target.router').transitionTo('image', queue, task, image);
   }
});
Run Code Online (Sandbox Code Playgroud)
最后,这是我们的ImageRoute:
App.Image = Ember.Object.extend(); …Run Code Online (Sandbox Code Playgroud) javascript model-view-controller nested-routes ember.js ember-router