diff options
author | Vitaly Takmazov | 2017-03-29 12:52:41 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-03-29 12:52:41 +0300 |
commit | b8651556c21c83448e46b270ed7013f490e53a5d (patch) | |
tree | 67c77b763ccc9ff21c6760e9957789ea65f1f00b /juick-www/src/main/java/com/juick/www/controllers | |
parent | bb7b8ef32d3c5b0a421ec641564ade7ab6b09c31 (diff) |
juick-www: inject json mapper
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/controllers')
3 files changed, 9 insertions, 21 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/FacebookLogin.java b/juick-www/src/main/java/com/juick/www/controllers/FacebookLogin.java index b1d275b6..178f6762 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/FacebookLogin.java +++ b/juick-www/src/main/java/com/juick/www/controllers/FacebookLogin.java @@ -17,7 +17,6 @@ */ package com.juick.www.controllers; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.apis.FacebookApi; import com.github.scribejava.core.builder.ServiceBuilder; @@ -61,7 +60,8 @@ public class FacebookLogin { private final String FACEBOOK_APPID; private final String FACEBOOK_SECRET; private final String FACEBOOK_REDIRECT = "http://juick.com/_fblogin"; - private final ObjectMapper mapper; + @Inject + private ObjectMapper jsonMapper; private ServiceBuilder serviceBuilder; @Inject @@ -74,10 +74,6 @@ public class FacebookLogin { FACEBOOK_APPID = env.getProperty("facebook_appid"); FACEBOOK_SECRET = env.getProperty("facebook_secret"); serviceBuilder = new ServiceBuilder(); - mapper = new ObjectMapper(); - mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); } @RequestMapping(value = "/_fblogin", method = RequestMethod.GET) @@ -122,7 +118,7 @@ public class FacebookLogin { logger.error("FACEBOOK GRAPH ERROR"); throw new HttpBadRequestException(); } - User fb = mapper.readValue(graph, User.class); + User fb = jsonMapper.readValue(graph, User.class); long fbID = NumberUtils.toLong(fb.getId(), 0); if (fbID == 0 || StringUtils.isBlank(fb.getName()) || StringUtils.isBlank(fb.getLink())) { throw new HttpBadRequestException(); diff --git a/juick-www/src/main/java/com/juick/www/controllers/TwitterAuth.java b/juick-www/src/main/java/com/juick/www/controllers/TwitterAuth.java index 9b09539e..33f266b2 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/TwitterAuth.java +++ b/juick-www/src/main/java/com/juick/www/controllers/TwitterAuth.java @@ -1,6 +1,5 @@ package com.juick.www.controllers; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.apis.TwitterApi; import com.github.scribejava.core.builder.ServiceBuilder; @@ -33,7 +32,8 @@ public class TwitterAuth { private String consumerKey, consumerSecret; - private final ObjectMapper mapper; + @Inject + private ObjectMapper jsonMapper; @Inject UserService userService; @@ -42,10 +42,6 @@ public class TwitterAuth { public TwitterAuth(Environment env) { this.consumerKey = env.getProperty("twitter_consumer_key"); this.consumerSecret = env.getProperty("twitter_consumer_secret"); - mapper = new ObjectMapper(); - mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); } @RequestMapping(value = "/_twitter", method = RequestMethod.GET) @@ -90,7 +86,7 @@ public class TwitterAuth { OAuth1AccessToken accessToken = oAuthService.getAccessToken(requestToken, verifier); OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, VERIFY_URL); oAuthService.signRequest(accessToken, oAuthRequest); - com.juick.www.twitter.User twitterUser = mapper.readValue(oAuthService.execute(oAuthRequest).getBody(), + com.juick.www.twitter.User twitterUser = jsonMapper.readValue(oAuthService.execute(oAuthRequest).getBody(), com.juick.www.twitter.User.class); if (userService.linkTwitterAccount(user, accessToken.getToken(), accessToken.getTokenSecret(), twitterUser.getScreenName())) { diff --git a/juick-www/src/main/java/com/juick/www/controllers/VKontakteLogin.java b/juick-www/src/main/java/com/juick/www/controllers/VKontakteLogin.java index e0a39220..efc86f7c 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/VKontakteLogin.java +++ b/juick-www/src/main/java/com/juick/www/controllers/VKontakteLogin.java @@ -17,7 +17,6 @@ */ package com.juick.www.controllers; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.apis.VkontakteApi; import com.github.scribejava.core.builder.ServiceBuilder; @@ -71,13 +70,10 @@ public class VKontakteLogin { VK_APPID = env.getProperty("vk_appid"); VK_SECRET = env.getProperty("vk_secret"); serviceBuilder = new ServiceBuilder(); - mapper = new ObjectMapper(); - mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); } - private final ObjectMapper mapper; + @Inject + private ObjectMapper jsonMapper; @RequestMapping(value = "/_vklogin", method = RequestMethod.GET) protected String doGet(HttpServletRequest request, @@ -117,7 +113,7 @@ public class VKontakteLogin { vkService.signRequest(token, meRequest); String graph = vkService.execute(meRequest).getBody(); - com.juick.www.vk.User jsonUser = mapper.readValue(graph, UsersResponse.class).getUsers().get(0); + com.juick.www.vk.User jsonUser = jsonMapper.readValue(graph, UsersResponse.class).getUsers().get(0); String vkName = jsonUser.getFirstName() + " " + jsonUser.getLastName(); String vkLink = jsonUser.getScreenName(); |