| | |
| | | package com.yeshi.buwan.controller.api; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.*; |
| | | import com.yeshi.buwan.controller.parser.UserParser; |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | import com.yeshi.buwan.domain.user.LoginUserExtra; |
| | |
| | | import com.yeshi.buwan.util.factory.vo.UserInfoVOFactory; |
| | | import com.yeshi.buwan.vo.AcceptData; |
| | | import com.yeshi.buwan.vo.client.user.UserInfoVO; |
| | | import org.json.JSONObject; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.lang.reflect.Type; |
| | | import java.text.DateFormat; |
| | | import java.util.Date; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/v2/user") |
| | |
| | | loginUserService.setUtdId(loginUid, acceptData.getUtdId()); |
| | | } |
| | | }); |
| | | |
| | | return JsonUtil.loadTrueJson(new Gson().toJson(vo)); |
| | | if ("ios".equalsIgnoreCase(acceptData.getPlatform())) { |
| | | if(StringUtil.isNullOrEmpty(vo.getBirthday())){ |
| | | vo.setBirthday(loginUser.getBirthday()); |
| | | } |
| | | if(StringUtil.isNullOrEmpty(vo.getSex())){ |
| | | vo.setSex(loginUser.getSex()); |
| | | } |
| | | if(StringUtil.isNullOrEmpty(vo.getSign())){ |
| | | vo.setSign(loginUser.getSign()); |
| | | } |
| | | Gson gson = new GsonBuilder().enableComplexMapKeySerialization() |
| | | .setDateFormat(DateFormat.LONG).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | @Override |
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive("0"); |
| | | } else { |
| | | return new JsonPrimitive(value.getTime()); |
| | | } |
| | | } |
| | | }).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 会把字段首字母大写 |
| | | .setPrettyPrinting().setVersion(1.0).create(); |
| | | net.sf.json.JSONObject root= net.sf.json.JSONObject.fromObject(gson.toJson(vo)); |
| | | root.put("Nickname",vo.getNickName()); |
| | | return JsonUtil.loadTrueJson(root.toString()); |
| | | } else { |
| | | return JsonUtil.loadTrueJson(new Gson().toJson(vo)); |
| | | } |
| | | } |
| | | |
| | | |