From: Gustavo Martin Morcuende Date: Tue, 4 Oct 2016 23:49:25 +0000 (+0200) Subject: API: return JSON when no Accept header from client X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=146bf1cc2d9eacd446f1cc0fec53b05078b83490;p=WebAppTest%2F.git API: return JSON when no Accept header from client --- 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;