10
10
import com .google .appengine .api .users .UserService ;
11
11
import com .google .appengine .api .users .UserServiceFactory ;
12
12
import com .google .gson .Gson ;
13
+ import com .google .gson .GsonBuilder ;
14
+ import com .pscuderi .appengineangulardemo .model .AppUser ;
15
+ import com .pscuderi .appengineangulardemo .service .AppUserService ;
13
16
14
17
public final class ServletUtils {
15
18
private ServletUtils () { }
16
19
17
20
private static Gson gson = new Gson ();
21
+ private static Gson customGson = new GsonBuilder ().excludeFieldsWithoutExposeAnnotation ().create ();
18
22
19
23
public static String toJson (Object o ) {
20
24
return gson .toJson (o );
21
25
}
26
+
27
+ public static String toCustomJson (Object o ) {
28
+ return customGson .toJson (o );
29
+ }
22
30
23
31
public static <T > T fromJson (String json , Class <T > clazz ) {
24
32
return gson .fromJson (json , clazz );
@@ -40,12 +48,15 @@ public static <T> T fromJson(BufferedReader reader, Class<T> clazz) throws IOExc
40
48
return fromJson (sb .toString (), clazz );
41
49
}
42
50
43
- public static User getUserAndRedirectIfNotAuthenticated (HttpServletRequest req , HttpServletResponse resp ) throws IOException {
51
+ public static AppUser getUserAndRedirectIfNotAuthenticated (HttpServletRequest req , HttpServletResponse resp ) throws IOException {
44
52
UserService userService = UserServiceFactory .getUserService ();
45
53
User user = userService .getCurrentUser ();
54
+
46
55
if (user == null ) {
47
56
resp .sendRedirect (userService .createLoginURL (req .getRequestURI ()));
57
+ return null ;
48
58
}
49
- return user ;
59
+
60
+ return AppUserService .getAppUser (user );
50
61
}
51
62
}
0 commit comments