From 146bf1cc2d9eacd446f1cc0fec53b05078b83490 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Wed, 5 Oct 2016 01:49:25 +0200 Subject: [PATCH] API: return JSON when no Accept header from client --- .../controllers/serializers/AccountResourceSerializer.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prueba/controllers/serializers/AccountResourceSerializer.java b/src/main/java/com/prueba/controllers/serializers/AccountResourceSerializer.java index 3eac8e0..07fc2bf 100644 --- a/src/main/java/com/prueba/controllers/serializers/AccountResourceSerializer.java +++ b/src/main/java/com/prueba/controllers/serializers/AccountResourceSerializer.java @@ -24,17 +24,15 @@ public class AccountResourceSerializer { final Headers headers = httpExchange.getRequestHeaders(); final String accept = headers.getFirst(ACCEPT_HEADER); - String serializedAccount = ""; - if (accept.equals(AccountResourceSerializer.CONTENT_TYPE_JSON)) { - serializedAccount = this.jsonSerializer(accountResource); - - this.setJSONContentType(httpExchange, CONTENT_TYPE_JSON); - } - + String serializedAccount; if (accept.equals(AccountResourceSerializer.CONTENT_TYPE_XML)) { serializedAccount = this.xmlSerializer(accountResource); this.setJSONContentType(httpExchange, CONTENT_TYPE_XML); + } else { + serializedAccount = this.jsonSerializer(accountResource); + + this.setJSONContentType(httpExchange, CONTENT_TYPE_JSON); } return serializedAccount; -- 2.1.4