API: return JSON when no Accept header from client
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Tue, 4 Oct 2016 23:49:25 +0000 (01:49 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Tue, 4 Oct 2016 23:49:25 +0000 (01:49 +0200)
src/main/java/com/prueba/controllers/serializers/AccountResourceSerializer.java

index 3eac8e0..07fc2bf 100644 (file)
@@ -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;