From 1f3e8ef58cd3c1b65fe587aab5e0b582612168cc Mon Sep 17 00:00:00 2001 From: Jon Brisbin Date: Wed, 18 Apr 2012 11:23:57 -0500 Subject: [PATCH] Fixed a bug in dealing with PUT/update --- .../rest/webmvc/RepositoryRestController.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java index 43011e870..31c7547f0 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java @@ -392,11 +392,11 @@ public class RepositoryRestController implements InitializingBean { } else { final MediaType incomingMediaType = request.getHeaders().getContentType(); try { - if (request.getMethod() == HttpMethod.POST) { - final Object incoming = readIncoming(request, incomingMediaType, typeMeta.domainClass); - if (null == incoming) { - model.addAttribute(STATUS, HttpStatus.BAD_REQUEST); - } else { + final Object incoming = readIncoming(request, incomingMediaType, typeMeta.domainClass); + if (null == incoming) { + model.addAttribute(STATUS, HttpStatus.BAD_REQUEST); + } else { + if (request.getMethod() == HttpMethod.POST) { typeMeta.entityMetadata.id(serId, incoming); Object savedEntity = repo.save(entity); String savedId = typeMeta.entityInfo.getId(savedEntity).toString(); @@ -405,23 +405,19 @@ public class RepositoryRestController implements InitializingBean { headers.set(LOCATION, selfUri.toString()); model.addAttribute(HEADERS, headers); model.addAttribute(STATUS, HttpStatus.CREATED); - } - } else { - final Map incoming = readIncoming(request, incomingMediaType, Map.class); - if (null == incoming) { - model.addAttribute(STATUS, HttpStatus.BAD_REQUEST); + } else { for (Map.Entry entry : typeMeta.entityMetadata.embeddedAttributes().entrySet()) { String name = entry.getKey(); - if (incoming.containsKey(name)) { - typeMeta.entityMetadata.set(name, incoming.get(name), entity); + Object o = typeMeta.entityMetadata.get(name, incoming); + if (null != o) { + typeMeta.entityMetadata.set(name, o, entity); } } repo.save(entity); model.addAttribute(STATUS, HttpStatus.NO_CONTENT); } } - } catch (IOException e) { model.addAttribute(STATUS, HttpStatus.BAD_REQUEST); LOG.error(e.getMessage(), e);