Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ New accounts and subaccounts are now required to use TLS 1.2 when accessing the

This library supports the following Java implementations:

- OpenJDK 8
- OpenJDK 11
- OpenJDK 17
- OracleJDK 8
- OracleJDK 11
- OracleJDK 17

For Java 7 support, use `twilio-java` major version `7.X.X`.
**Note:** As of version 12.0.0, this library requires **Java 17 or higher** due to the migration to Jackson 3.0.

For Java 8-11 support, use `twilio-java` version `11.X.X`.

### Beta Annotation

Expand Down
24 changes: 10 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
</profile>
</profiles>
<properties>
<jackson.version>2.15.0</jackson.version>
<jackson.version>3.0.4</jackson.version>
<jackson.annotations.version>2.20</jackson.annotations.version>
<javadoc.plugin.version>3.3.1</javadoc.plugin.version>
<jjwt.version>0.12.6</jjwt.version>
<skip.tests>false</skip.tests>
Expand Down Expand Up @@ -232,28 +233,23 @@
<artifactId>httpcore5</artifactId>
<version>5.3.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
<version>${jackson.annotations.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<groupId>tools.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>
Expand Down Expand Up @@ -349,8 +345,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>17</source>
<target>17</target>
<showDeprecation>true</showDeprecation>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/twilio/base/Page.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.twilio.base;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.JsonNode;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;
import com.twilio.exception.ApiConnectionException;
import com.twilio.exception.ApiException;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -138,11 +140,8 @@ public static <T> Page<T> fromJson(String recordKey, String json, Class<T> recor
} else {
return buildNextGenPage(root, results);
}

} catch (final IOException e) {
throw new ApiConnectionException(
"Unable to deserialize response: " + e.getMessage() + "\nJSON: " + json, e
);
} catch (JacksonException e) {
throw new ApiException("Unable to deserialize response: " + e.getMessage() + "\nJSON: " + json, e);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/twilio/base/TokenPaginationPage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.twilio.base;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.JsonNode;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;
import com.twilio.exception.ApiConnectionException;
import com.twilio.exception.ApiException;
import lombok.Getter;
Expand Down Expand Up @@ -101,8 +102,7 @@ public static <T> TokenPaginationPage<T> fromJson(String recordKey, String json,
} catch (NullPointerException e) {
throw new ApiException("Key not found", e);
}

} catch (final IOException e) {
} catch (JacksonException e) {
throw new ApiConnectionException(
"Unable to deserialize response: " + e.getMessage() + "\nJSON: " + json, e
);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/twilio/converter/Converter.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.twilio.converter;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -48,14 +48,14 @@ public static String objectToJson(Object value) {
if (value instanceof Collection || value instanceof Map) {
try {
return MAPPER.writeValueAsString(value);
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
return value.toString();
}
}
// Fallback: Try JSON, else toString
try {
return MAPPER.writeValueAsString(value);
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
return value.toString();
}
}
Expand All @@ -69,7 +69,7 @@ public static String objectToJson(Object value) {
public static String mapToJson(final Map<String, ? extends Object> map) {
try {
return MAPPER.writeValueAsString(map);
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
return null;
}
}
Expand All @@ -83,7 +83,7 @@ public static String mapToJson(final Map<String, ? extends Object> map) {
public static Map<String, Object> jsonToMap(final String json) {
try {
return MAPPER.readValue(json, HashMap.class);
} catch (IOException e) {
} catch (JacksonException e) {
return null;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/twilio/converter/CurrencyDeserializer.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.twilio.converter;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.ValueDeserializer;


import java.io.IOException;
import java.util.Currency;

public class CurrencyDeserializer extends JsonDeserializer<Currency> {
public class CurrencyDeserializer extends ValueDeserializer<Currency> {

@Override
public Currency deserialize(JsonParser jsonParser,
DeserializationContext deserializationContext) throws IOException {
DeserializationContext deserializationContext) {

String currencyCode = jsonParser.readValueAs(String.class);
return Currency.getInstance(currencyCode.toUpperCase());
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/twilio/converter/ISO8601Deserializer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.twilio.converter;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.ValueDeserializer;

import java.io.IOException;
import java.time.ZonedDateTime;

// open-api spec "format: date-time"
public class ISO8601Deserializer extends JsonDeserializer<ZonedDateTime> {
public class ISO8601Deserializer extends ValueDeserializer<ZonedDateTime> {
@Override
public ZonedDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException {
public ZonedDateTime deserialize(JsonParser parser, DeserializationContext context) {
String dateString = parser.getText();
return DateConverter.iso8601DateTimeFromString(dateString);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/twilio/converter/LocalDateDeserializer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.twilio.converter;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.ValueDeserializer;


import java.io.IOException;
import java.time.LocalDate;

// open-api spec "format: date"
public class LocalDateDeserializer extends JsonDeserializer<LocalDate> {
public class LocalDateDeserializer extends ValueDeserializer<LocalDate> {
@Override
public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException {
public LocalDate deserialize(JsonParser parser, DeserializationContext context) {
String dateString = parser.getText();
return DateConverter.localDateFromString(dateString);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/twilio/converter/RFC2822Deserializer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.twilio.converter;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.ValueDeserializer;


import java.io.IOException;
import java.time.ZonedDateTime;

// open-api spec "format: date-time-rfc-2822"
public class RFC2822Deserializer extends JsonDeserializer<ZonedDateTime> {
public class RFC2822Deserializer extends ValueDeserializer<ZonedDateTime> {
@Override
public ZonedDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException {
public ZonedDateTime deserialize(JsonParser parser, DeserializationContext context) {
String dateString = parser.getText();
return DateConverter.rfc2822DateTimeFromString(dateString);
}
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/twilio/converter/Serializer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.twilio.converter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.DatabindException;
import tools.jackson.databind.ObjectMapper;
import com.twilio.constant.EnumConstants.ParameterType;
import com.twilio.exception.ApiConnectionException;
import com.twilio.exception.ApiException;
Expand Down Expand Up @@ -38,12 +38,8 @@ public static <T> void toString(Request request, ObjectMapper mapper, T value) {
public static String toJson(Object object, ObjectMapper mapper) {
try {
return mapper.writeValueAsString(object);
} catch (final JsonMappingException e) {
} catch (JacksonException e) {
throw new ApiException(e.getMessage(), e);
} catch (JsonProcessingException e) {
throw new ApiException(e.getMessage(), e);
} catch (final IOException e) {
throw new ApiConnectionException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.twilio.converter;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import tools.jackson.core.JsonParser;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.ValueDeserializer;


import java.io.IOException;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;

public class ZonedDateTimeListDeserializer extends JsonDeserializer<List<ZonedDateTime>> {
public class ZonedDateTimeListDeserializer extends ValueDeserializer<List<ZonedDateTime>> {

@Override
public List<ZonedDateTime> deserialize(JsonParser parser, DeserializationContext context) throws IOException {
public List<ZonedDateTime> deserialize(JsonParser parser, DeserializationContext context) {
List<String> dateStrings = parser.readValueAs(new TypeReference<List<String>>() {
});
List<ZonedDateTime> dates = new ArrayList<>();
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/twilio/exception/RestException.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.exc.StreamReadException;
import tools.jackson.databind.DatabindException;
import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -53,10 +53,8 @@ public static RestException fromJson(final InputStream json, final ObjectMapper
// Convert all checked exception to Runtime
try {
return objectMapper.readValue(json, RestException.class);
} catch (final JsonMappingException | JsonParseException e) {
} catch (final DatabindException | StreamReadException e) {
throw new ApiException(e.getMessage(), e);
} catch (final IOException e) {
throw new ApiConnectionException(e.getMessage(), e);
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/twilio/exception/RestStandardException.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.exc.StreamReadException;
import tools.jackson.databind.DatabindException;
import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -103,10 +103,8 @@ private RestStandardException(
public static RestStandardException fromJson(final InputStream json, final ObjectMapper objectMapper) {
try {
return objectMapper.readValue(json, RestStandardException.class);
} catch (final JsonMappingException | JsonParseException e) {
} catch (final DatabindException | StreamReadException e) {
throw new ApiException(e.getMessage(), e);
} catch (final IOException e) {
throw new ApiConnectionException(e.getMessage(), e);
}
}

Expand Down
11 changes: 3 additions & 8 deletions src/main/java/com/twilio/http/TwilioRestClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.twilio.http;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import tools.jackson.databind.ObjectMapper;
import com.twilio.auth_strategy.AuthStrategy;
import com.twilio.auth_strategy.NoAuthStrategy;
import com.twilio.constant.EnumConstants;
Expand Down Expand Up @@ -138,12 +137,8 @@ public Response request(final Request request) {
}

public static class Builder {
// This module configures the ObjectMapper to use
// public API methods for manipulating java.time.*
// classes. The alternative is to use reflection which
// generates warnings from the module system on Java 9+
private static final ObjectMapper DEFAULT_OBJECT_MAPPER = new ObjectMapper()
.registerModule(new JavaTimeModule());
// Java 8 time support is now built into Jackson 3 databind
private static final ObjectMapper DEFAULT_OBJECT_MAPPER = new ObjectMapper();

private String username;
private String password;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/twilio/jwt/taskrouter/Policy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;
import com.twilio.http.HttpMethod;

import java.io.ByteArrayOutputStream;
Expand Down
Loading
Loading