Skip to content

Commit 493d6e3

Browse files
authored
Merge pull request #254 from kazuki-ma/UseBuilder
Use builder style in model/event class to make adding field more easyly and safely.
2 parents 8226d44 + 05571de commit 493d6e3

36 files changed

+479
-386
lines changed

line-bot-model/src/main/java/com/linecorp/bot/model/event/AccountLinkEvent.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.time.Instant;
2020

21-
import com.fasterxml.jackson.annotation.JsonProperty;
2221
import com.fasterxml.jackson.annotation.JsonTypeName;
2322
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2423
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -35,12 +34,18 @@
3534
* Event object for when a user has linked his/her LINE account with a provider's service account.
3635
* You can reply to account link events.
3736
*/
38-
@Value
39-
@Builder
40-
@AllArgsConstructor(access = AccessLevel.PRIVATE)
4137
@JsonTypeName("accountLink")
38+
@Value
39+
@Builder(toBuilder = true)
40+
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@Deprecated))
41+
// TODO: Remove next release. Use builder() instead.
4242
@JsonDeserialize(builder = AccountLinkEvent.AccountLinkEventBuilder.class)
4343
public class AccountLinkEvent implements Event, ReplyEvent {
44+
@JsonPOJOBuilder(withPrefix = "")
45+
public static class AccountLinkEventBuilder {
46+
// Providing builder instead of public constructor. Class body is filled by lombok.
47+
}
48+
4449
/**
4550
* Token for replying to this event.
4651
*/
@@ -81,15 +86,10 @@ public class AccountLinkEvent implements Event, ReplyEvent {
8186
*/
8287
@Deprecated
8388
public AccountLinkEvent(
84-
@JsonProperty("replyToken") String replyToken,
85-
@JsonProperty("source") Source source,
86-
@JsonProperty("timestamp") Instant timestamp,
87-
@JsonProperty("link") LinkContent link) {
89+
String replyToken,
90+
Source source,
91+
Instant timestamp,
92+
LinkContent link) {
8893
this(replyToken, source, timestamp, link, null);
8994
}
90-
91-
@JsonPOJOBuilder(withPrefix = "")
92-
public static class AccountLinkEventBuilder {
93-
// Filled by lombok
94-
}
9595
}

line-bot-model/src/main/java/com/linecorp/bot/model/event/BeaconEvent.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.time.Instant;
2020

21-
import com.fasterxml.jackson.annotation.JsonProperty;
2221
import com.fasterxml.jackson.annotation.JsonTypeName;
2322
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2423
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -34,12 +33,18 @@
3433
/**
3534
* Event object for when a user detects a LINE Beacon. You can reply to beacon events.
3635
*/
37-
@Value
38-
@Builder
39-
@AllArgsConstructor(access = AccessLevel.PRIVATE)
4036
@JsonTypeName("beacon")
37+
@Value
38+
@Builder(toBuilder = true)
39+
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@Deprecated))
40+
// TODO: Remove next release. Use builder() instead.
4141
@JsonDeserialize(builder = BeaconEvent.BeaconEventBuilder.class)
4242
public class BeaconEvent implements Event, ReplyEvent {
43+
@JsonPOJOBuilder(withPrefix = "")
44+
public static class BeaconEventBuilder {
45+
// Providing builder instead of public constructor. Class body is filled by lombok.
46+
}
47+
4348
/**
4449
* Token for replying to this event.
4550
*/
@@ -80,15 +85,10 @@ public class BeaconEvent implements Event, ReplyEvent {
8085
*/
8186
@Deprecated
8287
public BeaconEvent(
83-
@JsonProperty("replyToken") final String replyToken,
84-
@JsonProperty("source") final Source source,
85-
@JsonProperty("timestamp") final Instant timestamp,
86-
@JsonProperty("beacon") final BeaconContent beacon) {
88+
final String replyToken,
89+
final Source source,
90+
final Instant timestamp,
91+
final BeaconContent beacon) {
8792
this(replyToken, source, beacon, timestamp, null);
8893
}
89-
90-
@JsonPOJOBuilder(withPrefix = "")
91-
public static class BeaconEventBuilder {
92-
// Filled by lombok
93-
}
9494
}

line-bot-model/src/main/java/com/linecorp/bot/model/event/CallbackRequest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@
1818

1919
import java.util.List;
2020

21-
import com.fasterxml.jackson.annotation.JsonCreator;
22-
import com.fasterxml.jackson.annotation.JsonProperty;
21+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
22+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
2323

24+
import lombok.AllArgsConstructor;
25+
import lombok.Builder;
2426
import lombok.Value;
2527

2628
/**
2729
* Request object for webhook.
2830
*/
2931
@Value
32+
@Builder(toBuilder = true)
33+
@AllArgsConstructor(onConstructor = @__(@Deprecated)) // TODO: Remove next release. Use builder() instead.
34+
@JsonDeserialize(builder = CallbackRequest.CallbackRequestBuilder.class)
3035
public class CallbackRequest {
36+
@JsonPOJOBuilder(withPrefix = "")
37+
public static class CallbackRequestBuilder {
38+
// Providing builder instead of public constructor. Class body is filled by lombok.
39+
}
40+
3141
/**
3242
* A user ID of a bot that should receive webhook events. The user ID value is
3343
* a string that matches the regular expression, {@code U[0-9a-f]{32}}.
@@ -38,11 +48,4 @@ public class CallbackRequest {
3848
* List of events.
3949
*/
4050
List<Event> events;
41-
42-
@JsonCreator
43-
public CallbackRequest(@JsonProperty("events") final List<Event> events,
44-
@JsonProperty("destination") final String destination) {
45-
this.events = events;
46-
this.destination = destination;
47-
}
4851
}

line-bot-model/src/main/java/com/linecorp/bot/model/event/FollowEvent.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.time.Instant;
2020

21-
import com.fasterxml.jackson.annotation.JsonProperty;
2221
import com.fasterxml.jackson.annotation.JsonTypeName;
2322
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2423
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -33,12 +32,18 @@
3332
/**
3433
* Event object for when your account is added as a friend (or unblocked). You can reply to follow events.
3534
*/
36-
@Value
37-
@Builder
38-
@AllArgsConstructor(access = AccessLevel.PRIVATE)
3935
@JsonTypeName("follow")
36+
@Value
37+
@Builder(toBuilder = true)
38+
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@Deprecated))
39+
// TODO: Remove next release. Use builder() instead.
4040
@JsonDeserialize(builder = FollowEvent.FollowEventBuilder.class)
4141
public class FollowEvent implements Event, ReplyEvent {
42+
@JsonPOJOBuilder(withPrefix = "")
43+
public static class FollowEventBuilder {
44+
// Providing builder instead of public constructor. Class body is filled by lombok.
45+
}
46+
4247
/**
4348
* Token for replying to this event.
4449
*/
@@ -74,14 +79,9 @@ public class FollowEvent implements Event, ReplyEvent {
7479
*/
7580
@Deprecated
7681
public FollowEvent(
77-
@JsonProperty("replyToken") final String replyToken,
78-
@JsonProperty("source") final Source source,
79-
@JsonProperty("timestamp") final Instant timestamp) {
82+
final String replyToken,
83+
final Source source,
84+
final Instant timestamp) {
8085
this(replyToken, source, timestamp, null);
8186
}
82-
83-
@JsonPOJOBuilder(withPrefix = "")
84-
public static class FollowEventBuilder {
85-
// Filled by lombok
86-
}
8787
}

line-bot-model/src/main/java/com/linecorp/bot/model/event/JoinEvent.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.time.Instant;
2020

21-
import com.fasterxml.jackson.annotation.JsonProperty;
2221
import com.fasterxml.jackson.annotation.JsonTypeName;
2322
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2423
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -33,12 +32,18 @@
3332
/**
3433
* Event object for when your account joins a group or talk room. You can reply to join events.
3534
*/
36-
@Value
37-
@Builder
38-
@AllArgsConstructor(access = AccessLevel.PRIVATE)
3935
@JsonTypeName("join")
36+
@Value
37+
@Builder(toBuilder = true)
38+
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@Deprecated))
39+
// TODO: Remove next release. Use builder() instead.
4040
@JsonDeserialize(builder = JoinEvent.JoinEventBuilder.class)
4141
public class JoinEvent implements Event, ReplyEvent {
42+
@JsonPOJOBuilder(withPrefix = "")
43+
public static class JoinEventBuilder {
44+
// Providing builder instead of public constructor. Class body is filled by lombok.
45+
}
46+
4247
/**
4348
* Token for replying to this event.
4449
*/
@@ -74,14 +79,9 @@ public class JoinEvent implements Event, ReplyEvent {
7479
*/
7580
@Deprecated
7681
public JoinEvent(
77-
@JsonProperty("replyToken") final String replyToken,
78-
@JsonProperty("source") final Source source,
79-
@JsonProperty("timestamp") final Instant timestamp) {
82+
final String replyToken,
83+
final Source source,
84+
final Instant timestamp) {
8085
this(replyToken, source, timestamp, null);
8186
}
82-
83-
@JsonPOJOBuilder(withPrefix = "")
84-
public static class JoinEventBuilder {
85-
// Filled by lombok
86-
}
8787
}

line-bot-model/src/main/java/com/linecorp/bot/model/event/LeaveEvent.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.time.Instant;
2020

21-
import com.fasterxml.jackson.annotation.JsonProperty;
2221
import com.fasterxml.jackson.annotation.JsonTypeName;
2322
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2423
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -33,12 +32,18 @@
3332
/**
3433
* Event object for when your account leaves a group.
3534
*/
36-
@Value
37-
@Builder
38-
@AllArgsConstructor(access = AccessLevel.PRIVATE)
3935
@JsonTypeName("leave")
36+
@Value
37+
@Builder(toBuilder = true)
38+
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@Deprecated))
39+
// TODO: Remove next release. Use builder() instead.
4040
@JsonDeserialize(builder = LeaveEvent.LeaveEventBuilder.class)
4141
public class LeaveEvent implements Event {
42+
@JsonPOJOBuilder(withPrefix = "")
43+
public static class LeaveEventBuilder {
44+
// Providing builder instead of public constructor. Class body is filled by lombok.
45+
}
46+
4247
/**
4348
* JSON object which contains the source of the event.
4449
*/
@@ -69,13 +74,8 @@ public class LeaveEvent implements Event {
6974
*/
7075
@Deprecated
7176
public LeaveEvent(
72-
@JsonProperty("source") final Source source,
73-
@JsonProperty("timestamp") final Instant timestamp) {
77+
final Source source,
78+
final Instant timestamp) {
7479
this(source, timestamp, null);
7580
}
76-
77-
@JsonPOJOBuilder(withPrefix = "")
78-
public static class LeaveEventBuilder {
79-
// Filled by lombok
80-
}
8181
}

line-bot-model/src/main/java/com/linecorp/bot/model/event/MemberJoinedEvent.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import java.time.Instant;
2020
import java.util.List;
2121

22-
import com.fasterxml.jackson.annotation.JsonCreator;
23-
import com.fasterxml.jackson.annotation.JsonProperty;
2422
import com.fasterxml.jackson.annotation.JsonTypeName;
2523
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2624
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -35,12 +33,18 @@
3533
/**
3634
* Event object for when a user joins a group or room that the bot is in.
3735
*/
38-
@Value
39-
@Builder
40-
@AllArgsConstructor(access = AccessLevel.PRIVATE)
4136
@JsonTypeName("memberJoined")
37+
@Value
38+
@Builder(toBuilder = true)
39+
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@Deprecated))
40+
// TODO: Remove next release. Use builder() instead.
4241
@JsonDeserialize(builder = MemberJoinedEvent.MemberJoinedEventBuilder.class)
4342
public class MemberJoinedEvent implements Event, ReplyEvent {
43+
@JsonPOJOBuilder(withPrefix = "")
44+
public static class MemberJoinedEventBuilder {
45+
// Providing builder instead of public constructor. Class body is filled by lombok.
46+
}
47+
4448
/**
4549
* Token for replying to this event.
4650
*/
@@ -81,26 +85,25 @@ public class MemberJoinedEvent implements Event, ReplyEvent {
8185
*/
8286
@Deprecated
8387
public MemberJoinedEvent(
84-
@JsonProperty("replyToken") final String replyToken,
85-
@JsonProperty("source") final Source source,
86-
@JsonProperty("joined") final JoinedMembers joined,
87-
@JsonProperty("timestamp") final Instant timestamp) {
88+
final String replyToken,
89+
final Source source,
90+
final JoinedMembers joined,
91+
final Instant timestamp) {
8892
this(replyToken, source, timestamp, joined, null);
8993
}
9094

91-
@JsonPOJOBuilder(withPrefix = "")
92-
public static class MemberJoinedEventBuilder {
93-
// Filled by lombok
94-
}
95-
9695
@Value
96+
@Builder(toBuilder = true)
97+
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@Deprecated))
98+
// TODO: Remove next release. Use builder() instead.
99+
@JsonDeserialize(builder = JoinedMembers.JoinedMembersBuilder.class)
97100
public static class JoinedMembers {
101+
@JsonPOJOBuilder(withPrefix = "")
102+
public static class JoinedMembersBuilder {
103+
// Providing builder instead of public constructor. Class body is filled by lombok.
104+
}
105+
98106
// User ID of users who joined
99107
List<Source> members;
100-
101-
@JsonCreator
102-
public JoinedMembers(@JsonProperty("members") List<Source> members) {
103-
this.members = members;
104-
}
105108
}
106109
}

0 commit comments

Comments
 (0)