blob: 92602ff2df4bd13a130c6dab423028f2f6b7e011 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package org.openslx.taskmanager.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Util
{
private static GsonBuilder gsonBuilder = new GsonBuilder();
/**
* Small helper to create a gson instance that will only handle class members with the
* "@Exposed" annotation. Decided against the default of explicitly excluding fields by
* making them transient, as you might easily forget to exclude an important field, which
* can in turn be a security issue.
*
* @return Gson instance
*/
public static Gson explicitGsonInstance()
{
return gsonBuilder
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter( byte[].class, new ByteArrayDeserializer() )
.create();
}
public static int parseInt(String str, int def)
{
try {
return Integer.parseInt( str );
} catch (Throwable t) {
return def;
}
}
}
|