-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathGsonFactory.java
More file actions
53 lines (47 loc) · 2.73 KB
/
GsonFactory.java
File metadata and controls
53 lines (47 loc) · 2.73 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
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 createSnakeCase(boolean failOnUnknownProperties, boolean unknownPropertyDetection) {
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) {
return builder.registerTypeAdapterFactory(new UnknownPropertyDetectionAdapterFactory()).create();
} else {
return builder.create();
}
}
}