kopi_b kopi_b - 20 days ago 10
JSON Question

AngularJS $resource and JAX-RS

i made a small webapp using AngularJS, JAX-RS and Hibernate. I'm trying to get and save objects of my type 'Plugin'. Getting works fine but saving doesn't. When i look at the object on the server, it's initialized but all the properties are null expect for the title property of type String which is set to the json string of the whole object.

{"id":"22a7533fb6-...", "title":"My Plugin"}


function save(plugin) {
return $resource('rest/plugins/save', { plugin: plugin }, {
save : {
method : 'PUT',
isArray : false


public void savePlugin(@Context HttpServletRequest req, @QueryParam("plugin") Plugin plugin) throws IOException {
log.debug("plugin..." + plugin.getTitle());


@Table(name = "plugin")
public class Plugin {

@Column(name = "id", unique = true, length = 36, nullable = false)
private String id;

@Column(name = "title", unique = true, length = 255, nullable = false)
private String title;

// getters and setters without any annotations...

Looking at the plugin variable in the javascript, it's the full object. And the request is

Request URL:/rest/plugins/save?plugin=%7B%22id%22:%22a7533fb6-d36f-459b-b9e7-bb64cdaae1e3%22,%22title%22:%22My+Plugin%22%7D

Thanks for any help, kopi


You shouldn't send the Plugin as a query parameter. Send it in the request payload:

PUT /rest/plugins/save HTTP/1.1
Host: example.org
Content-Type: application/json

  "id": "22a7533fb6-d36f-459b-b9e7-bb64cdaae1e3",
  "title": "My Plugin"

Your resource method should be like:

public void savePlugin(@Context HttpServletRequest request,
                       Plugin plugin) throws IOException {