Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated joda time #173

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,10 @@ shadowJar {
}

dependencies {
// base
implementation 'joda-time:joda-time:2.9.9'

// persistence
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.10'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.9.10'
implementation 'com.fasterxml.jackson.core:jackson-core:2.17.1'
// Java 8 data/time serializer
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1'

// networking
implementation 'com.squareup.okhttp3:okhttp:3.7.0'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/co/omise/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import co.omise.models.*;
import co.omise.models.schedules.*;
import co.omise.requests.Request;
import org.joda.time.LocalDate;
import java.time.LocalDate;

import java.io.IOException;

Expand Down
27 changes: 8 additions & 19 deletions src/main/java/co/omise/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.fasterxml.jackson.datatype.joda.cfg.JacksonJodaDateFormat;
import com.fasterxml.jackson.datatype.joda.ser.DateTimeSerializer;
import com.fasterxml.jackson.datatype.joda.ser.LocalDateSerializer;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Map;

/**
Expand Down Expand Up @@ -53,19 +49,12 @@ public static Serializer defaultSerializer() {
private final DateTimeFormatter localDateFormatter;

private Serializer() {
dateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis();
localDateFormatter = ISODateTimeFormat.date();
dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss['Z']");
localDateFormatter = DateTimeFormatter.ISO_LOCAL_DATE;

objectMapper = new ObjectMapper()
.registerModule(new JodaModule()
.addSerializer(DateTime.class, new DateTimeSerializer()
.withFormat(new JacksonJodaDateFormat(dateTimeFormatter), 0)
)
.addSerializer(LocalDate.class, new LocalDateSerializer()
.withFormat(new JacksonJodaDateFormat(localDateFormatter), 0)
)
)

.registerModule(new JavaTimeModule()
.addSerializer(LocalDate.class, new LocalDateSerializer(localDateFormatter)))
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/co/omise/models/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;
import org.joda.time.YearMonth;
import java.time.YearMonth;

import java.io.IOException;

Expand Down Expand Up @@ -190,7 +190,7 @@ public void setStreet2(String street2) {

@JsonIgnore
public YearMonth getExpiration() {
return new YearMonth(expirationYear, expirationMonth);
return YearMonth.of(expirationYear, expirationMonth);
}

public static class Create extends co.omise.models.Params {
Expand Down Expand Up @@ -291,8 +291,8 @@ public Create street2(String street2) {
}

public Create expiration(YearMonth expiration) {
return expirationMonth(expiration.getMonthOfYear())
.expirationYear(expiration.getYear());
return expirationMonth(expiration.getMonthValue())
.expirationYear(expiration.getYear());
}

public Create expiration(int month, int year) {
Expand Down Expand Up @@ -404,8 +404,8 @@ public UpdateRequestBuilder postalCode(String postalCode) {
}

public UpdateRequestBuilder expiration(YearMonth expiration) {
return expirationMonth(expiration.getMonthOfYear())
.expirationYear(expiration.getYear());
return expirationMonth(expiration.getMonthValue())
.expirationYear(expiration.getYear());
}

public UpdateRequestBuilder expiration(int month, int year) {
Expand Down
31 changes: 15 additions & 16 deletions src/main/java/co/omise/models/Charge.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;
import org.joda.time.DateTime;

import java.time.ZonedDateTime;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -37,9 +36,9 @@ public class Charge extends Model {
private Dispute dispute;
private boolean expired;
@JsonProperty("expired_at")
private DateTime expiredAt;
private ZonedDateTime expiredAt;
@JsonProperty("expires_at")
private DateTime expiresAt;
private ZonedDateTime expiresAt;
@JsonProperty("failure_code")
private String failureCode;
@JsonProperty("failure_message")
Expand All @@ -61,7 +60,7 @@ public class Charge extends Model {
private long net;
private boolean paid;
@JsonProperty("paid_at")
private DateTime paidAt;
private ZonedDateTime paidAt;
@JsonProperty("platform_fee")
private PlatformFee platformFee;
private boolean refundable;
Expand All @@ -74,7 +73,7 @@ public class Charge extends Model {
private String returnUri;
private boolean reversed;
@JsonProperty("reversed_at")
private DateTime reversedAt;
private ZonedDateTime reversedAt;
private boolean reversible;
private String schedule;
private Source source;
Expand Down Expand Up @@ -207,19 +206,19 @@ public void setExpired(boolean expired) {
this.expired = expired;
}

public DateTime getExpiredAt() {
public ZonedDateTime getExpiredAt() {
return this.expiredAt;
}

public void setExpiredAt(DateTime expiredAt) {
public void setExpiredAt(ZonedDateTime expiredAt) {
this.expiredAt = expiredAt;
}

public DateTime getExpiresAt() {
public ZonedDateTime getExpiresAt() {
return this.expiresAt;
}

public void setExpiresAt(DateTime expiresAt) {
public void setExpiresAt(ZonedDateTime expiresAt) {
this.expiresAt = expiresAt;
}

Expand Down Expand Up @@ -335,11 +334,11 @@ public void setPaid(boolean paid) {
this.paid = paid;
}

public DateTime getPaidAt() {
public ZonedDateTime getPaidAt() {
return this.paidAt;
}

public void setPaidAt(DateTime paidAt) {
public void setPaidAt(ZonedDateTime paidAt) {
this.paidAt = paidAt;
}

Expand Down Expand Up @@ -391,11 +390,11 @@ public void setReversed(boolean reversed) {
this.reversed = reversed;
}

public DateTime getReversedAt() {
public ZonedDateTime getReversedAt() {
return this.reversedAt;
}

public void setReversedAt(DateTime reversedAt) {
public void setReversedAt(ZonedDateTime reversedAt) {
this.reversedAt = reversedAt;
}

Expand Down Expand Up @@ -553,7 +552,7 @@ public static class CreateRequestBuilder extends RequestBuilder<Charge> {
@JsonProperty
private String description;
@JsonProperty("expires_at")
private DateTime expiresAt;
private ZonedDateTime expiresAt;
@JsonProperty
private String ip;
@JsonProperty
Expand Down Expand Up @@ -616,7 +615,7 @@ public CreateRequestBuilder description(String description) {
return this;
}

public CreateRequestBuilder expiresAt(DateTime expiresAt) {
public CreateRequestBuilder expiresAt(ZonedDateTime expiresAt) {
this.expiresAt = expiresAt;
return this;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/co/omise/models/Dispute.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;
import org.joda.time.DateTime;
import java.time.ZonedDateTime;

import java.io.IOException;
import java.util.HashMap;
Expand All @@ -25,7 +25,7 @@ public class Dispute extends Model {
private long amount;
private String charge;
@JsonProperty("closed_at")
private DateTime closedAt;
private ZonedDateTime closedAt;
private String currency;
private ScopedList<Document> documents;
@JsonProperty("funding_amount")
Expand Down Expand Up @@ -66,11 +66,11 @@ public void setCharge(String charge) {
this.charge = charge;
}

public DateTime getClosedAt() {
public ZonedDateTime getClosedAt() {
return this.closedAt;
}

public void setClosedAt(DateTime closedAt) {
public void setClosedAt(ZonedDateTime closedAt) {
this.closedAt = closedAt;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/co/omise/models/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;
import org.joda.time.DateTime;
import java.time.ZonedDateTime;

import java.io.IOException;

Expand All @@ -28,7 +28,7 @@ public class Link extends Model {
private String title;
private boolean used;
@JsonProperty("used_at")
private DateTime usedAt;
private ZonedDateTime usedAt;

public long getAmount() {
return this.amount;
Expand Down Expand Up @@ -102,11 +102,11 @@ public void setUsed(boolean used) {
this.used = used;
}

public DateTime getUsedAt() {
public ZonedDateTime getUsedAt() {
return this.usedAt;
}

public void setUsedAt(DateTime usedAt) {
public void setUsedAt(ZonedDateTime usedAt) {
this.usedAt = usedAt;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/co/omise/models/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
import org.joda.time.DateTime;
import java.time.ZonedDateTime;

@JsonTypeInfo(
use = JsonTypeInfo.Id.CUSTOM,
Expand All @@ -17,7 +17,7 @@ public abstract class Model extends OmiseObjectBase {
@JsonProperty("livemode")
private boolean liveMode;
@JsonProperty("created_at")
private DateTime created;
private ZonedDateTime created;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private boolean deleted;

Expand All @@ -40,11 +40,11 @@ public void setLiveMode(boolean liveMode) {
this.liveMode = liveMode;
}

public DateTime getCreated() {
public ZonedDateTime getCreated() {
return created;
}

public void setCreated(DateTime created) {
public void setCreated(ZonedDateTime created) {
this.created = created;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/co/omise/models/Receipt.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;

import org.joda.time.LocalDate;
import java.time.LocalDate;

/**
* Receipt object
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/co/omise/models/Recipient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;
import org.joda.time.DateTime;

import java.time.ZonedDateTime;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -21,7 +20,7 @@
*/
public class Recipient extends Model {
@JsonProperty("activated_at")
private DateTime activatedAt;
private ZonedDateTime activatedAt;
private boolean active;
@JsonProperty("bank_account")
private BankAccount bankAccount;
Expand All @@ -40,13 +39,13 @@ public class Recipient extends Model {
private RecipientType type;
private boolean verified;
@JsonProperty("verified_at")
private DateTime verifiedAt;
private ZonedDateTime verifiedAt;

public DateTime getActivatedAt() {
public ZonedDateTime getActivatedAt() {
return this.activatedAt;
}

public void setActivatedAt(DateTime activatedAt) {
public void setActivatedAt(ZonedDateTime activatedAt) {
this.activatedAt = activatedAt;
}

Expand Down Expand Up @@ -154,11 +153,11 @@ public void setVerified(boolean verified) {
this.verified = verified;
}

public DateTime getVerifiedAt() {
public ZonedDateTime getVerifiedAt() {
return this.verifiedAt;
}

public void setVerifiedAt(DateTime verifiedAt) {
public void setVerifiedAt(ZonedDateTime verifiedAt) {
this.verifiedAt = verifiedAt;
}

Expand Down
Loading
Loading