-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathClientModule.java
More file actions
62 lines (55 loc) · 2.09 KB
/
ClientModule.java
File metadata and controls
62 lines (55 loc) · 2.09 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ua_parser;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.module.SimpleModule;
/**
* Class that registers capability of serializing objects with Jackson core.
*
* This module can be manually registered with Jackson:
* <pre>
* ObjectMapper mapper = new ObjectMapper();
* mapper.registerModule(new ClientModule());
* </pre>
*
* This module also supports auto configuration as an SPI via the Java ServiceLoader api:
* <pre>
* ObjectMapper mapper = new ObjectMapper();
* mapper.findAndRegisterModules();
*
* </pre>
*
* @author Adam J. Weigold
*/
public class ClientModule extends SimpleModule {
public ClientModule() {
setMixInAnnotation(UserAgent.class, UserAgentMixin.class);
setMixInAnnotation(OS.class, OSMixin.class);
setMixInAnnotation(Device.class, DeviceMixin.class);
setMixInAnnotation(Client.class, ClientMixin.class);
}
abstract static class UserAgentMixin {
@JsonCreator
public UserAgentMixin(@JsonProperty("family") String family,
@JsonProperty("major") String major,
@JsonProperty("minor") String minor,
@JsonProperty("patch") String patch) {}
}
abstract static class OSMixin {
@JsonCreator
public OSMixin(@JsonProperty("family") String family,
@JsonProperty("major") String major,
@JsonProperty("minor") String minor,
@JsonProperty("patch") String patch,
@JsonProperty("patchMinor") String patchMinor) {}
}
abstract static class DeviceMixin {
@JsonCreator
public DeviceMixin(@JsonProperty("family") String family) {}
}
abstract static class ClientMixin {
@JsonCreator
public ClientMixin(@JsonProperty("userAgent") UserAgent userAgent,
@JsonProperty("os") OS os,
@JsonProperty("device") Device device) {}
}
}