|
1 | | -package com.creatubbles.api.core; |
2 | | - |
3 | | -import java.lang.reflect.Type; |
4 | | - |
5 | | -import lombok.Builder; |
6 | | -import lombok.Value; |
7 | | - |
8 | | -import com.google.gson.JsonElement; |
9 | | -import com.google.gson.JsonObject; |
10 | | -import com.google.gson.JsonSerializationContext; |
11 | | -import com.google.gson.JsonSerializer; |
12 | | -import com.google.gson.annotations.SerializedName; |
13 | | - |
14 | | -@Value |
15 | | -@Builder |
16 | | -public class Gallery { |
17 | | - |
18 | | - int id; |
19 | | - String name, description; |
20 | | - |
21 | | - @SerializedName("type") |
22 | | - String type; |
23 | | - @SerializedName("created_at") |
24 | | - String createdDate; |
25 | | - Image banner; |
26 | | - |
27 | | - @SerializedName("open_for_all") |
28 | | - boolean openForAll; |
29 | | - |
30 | | - @SerializedName("owner_id") |
31 | | - int ownerId; |
32 | | - @SerializedName("owner_type") |
33 | | - String ownerType; |
34 | | - |
35 | | - public static class Serializer implements JsonSerializer<Gallery> { |
36 | | - |
37 | | - @Override |
38 | | - public JsonElement serialize(Gallery src, Type typeOfSrc, JsonSerializationContext context) { |
39 | | - |
40 | | - JsonObject root = new JsonObject(); |
41 | | - |
42 | | - JsonObject data = new JsonObject(); |
43 | | - data.addProperty("type", src.type); |
44 | | - |
45 | | - JsonObject attributes = new JsonObject(); |
46 | | - attributes.addProperty("name", src.name); |
47 | | - attributes.addProperty("descrtiption", src.description); |
48 | | - attributes.addProperty("open_for_all", src.openForAll ? 1 : 0); |
49 | | - |
50 | | - JsonObject relationships = new JsonObject(); |
51 | | - |
52 | | - JsonObject owner = new JsonObject(); |
53 | | - JsonObject ownerdata = new JsonObject(); |
54 | | - ownerdata.addProperty("type", src.ownerType); |
55 | | - ownerdata.addProperty("id", src.ownerId); |
56 | | - owner.add("data", ownerdata); |
57 | | - |
58 | | - relationships.add("owner", owner); |
59 | | - |
60 | | - data.add("attributes", attributes); |
61 | | - data.add("relationships", relationships); |
62 | | - |
63 | | - root.add("data", data); |
64 | | - return root; |
65 | | - } |
66 | | - } |
67 | | - |
68 | | -} |
| 1 | +package com.creatubbles.api.core; |
| 2 | + |
| 3 | +import java.lang.reflect.Type; |
| 4 | + |
| 5 | +import lombok.Builder; |
| 6 | +import lombok.EqualsAndHashCode; |
| 7 | +import lombok.Getter; |
| 8 | +import lombok.ToString; |
| 9 | + |
| 10 | +import com.google.gson.JsonElement; |
| 11 | +import com.google.gson.JsonObject; |
| 12 | +import com.google.gson.JsonSerializationContext; |
| 13 | +import com.google.gson.JsonSerializer; |
| 14 | +import com.google.gson.annotations.SerializedName; |
| 15 | + |
| 16 | +@ToString(callSuper = true) |
| 17 | +@EqualsAndHashCode |
| 18 | +@Builder |
| 19 | +@Getter |
| 20 | +public class Gallery { |
| 21 | + |
| 22 | + private int id; |
| 23 | + private String name, description; |
| 24 | + |
| 25 | + @SerializedName("type") |
| 26 | + private String type; |
| 27 | + @SerializedName("created_at") |
| 28 | + private String createdDate; |
| 29 | + private Image banner; |
| 30 | + |
| 31 | + @SerializedName("open_for_all") |
| 32 | + private boolean openForAll; |
| 33 | + |
| 34 | + @SerializedName("owner_id") |
| 35 | + private int ownerId; |
| 36 | + @SerializedName("owner_type") |
| 37 | + private String ownerType; |
| 38 | + |
| 39 | + public static class Serializer implements JsonSerializer<Gallery> { |
| 40 | + |
| 41 | + @Override |
| 42 | + public JsonElement serialize(Gallery src, Type typeOfSrc, JsonSerializationContext context) { |
| 43 | + |
| 44 | + JsonObject root = new JsonObject(); |
| 45 | + |
| 46 | + JsonObject data = new JsonObject(); |
| 47 | + data.addProperty("type", src.type); |
| 48 | + |
| 49 | + JsonObject attributes = new JsonObject(); |
| 50 | + attributes.addProperty("name", src.name); |
| 51 | + attributes.addProperty("descrtiption", src.description); |
| 52 | + attributes.addProperty("open_for_all", src.openForAll ? 1 : 0); |
| 53 | + |
| 54 | + JsonObject relationships = new JsonObject(); |
| 55 | + |
| 56 | + JsonObject owner = new JsonObject(); |
| 57 | + JsonObject ownerdata = new JsonObject(); |
| 58 | + ownerdata.addProperty("type", src.ownerType); |
| 59 | + ownerdata.addProperty("id", src.ownerId); |
| 60 | + owner.add("data", ownerdata); |
| 61 | + |
| 62 | + relationships.add("owner", owner); |
| 63 | + |
| 64 | + data.add("attributes", attributes); |
| 65 | + data.add("relationships", relationships); |
| 66 | + |
| 67 | + root.add("data", data); |
| 68 | + return root; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | +} |
0 commit comments