forked from slackapi/java-slack-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGsonFactory.java
More file actions
68 lines (59 loc) · 3.24 KB
/
GsonFactory.java
File metadata and controls
68 lines (59 loc) · 3.24 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
63
64
65
66
67
68
package test_locally.unit;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.slack.api.model.Attachment;
import com.slack.api.model.File;
import com.slack.api.model.block.ContextBlockElement;
import com.slack.api.model.block.ContextActionsBlockElement;
import com.slack.api.model.block.LayoutBlock;
import com.slack.api.model.block.composition.TextObject;
import com.slack.api.model.block.element.BlockElement;
import com.slack.api.model.block.element.RichTextElement;
import com.slack.api.model.event.FunctionExecutedEvent;
import com.slack.api.model.event.MessageChangedEvent;
import com.slack.api.util.json.*;
public class GsonFactory {
private GsonFactory() {
}
public static Gson createSnakeCase() {
return createSnakeCase(false, true);
}
public static Gson createSnakeCaseWithoutUnknownPropertyDetection(boolean failOnUnknownProperties) {
return createSnakeCase(failOnUnknownProperties, false);
}
public static Gson createSnakeCaseWithRequiredPropertyDetection() {
return createSnakeCase(false, true, true);
}
public static Gson createSnakeCase(boolean failOnUnknownProperties, boolean unknownPropertyDetection) {
return createSnakeCase(failOnUnknownProperties, unknownPropertyDetection, false);
}
public static Gson createSnakeCase(
boolean failOnUnknownProperties,
boolean unknownPropertyDetection,
boolean failOnRequiredProperties
) {
GsonBuilder builder = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.registerTypeAdapter(File.class, new GsonFileFactory(failOnUnknownProperties))
.registerTypeAdapter(LayoutBlock.class, new GsonLayoutBlockFactory(failOnUnknownProperties))
.registerTypeAdapter(BlockElement.class, new GsonBlockElementFactory(failOnUnknownProperties))
.registerTypeAdapter(ContextBlockElement.class, new GsonContextBlockElementFactory(failOnUnknownProperties))
.registerTypeAdapter(ContextActionsBlockElement.class, new GsonContextActionsBlockElementFactory(failOnUnknownProperties))
.registerTypeAdapter(TextObject.class, new GsonTextObjectFactory(failOnUnknownProperties))
.registerTypeAdapter(RichTextElement.class, new GsonRichTextElementFactory(failOnUnknownProperties))
.registerTypeAdapter(FunctionExecutedEvent.InputValue.class,
new GsonFunctionExecutedEventInputValueFactory(failOnUnknownProperties))
.registerTypeAdapter(Attachment.VideoHtml.class,
new GsonMessageAttachmentVideoHtmlFactory(failOnUnknownProperties))
.registerTypeAdapter(MessageChangedEvent.PreviousMessage.class,
new GsonMessageChangedEventPreviousMessageFactory(failOnUnknownProperties));
if (unknownPropertyDetection) {
builder.registerTypeAdapterFactory(new UnknownPropertyDetectionAdapterFactory());
}
if (failOnRequiredProperties) {
builder.registerTypeAdapterFactory(new RequiredPropertyDetectionAdapterFactory());
}
return builder.create();
}
}