1

I am using Java web in Netbeans 8.2 RC

I try to send an SMS message using Twillio client:

Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(
                new com.twilio.type.PhoneNumber(getContact()),
                new com.twilio.type.PhoneNumber("+phonenumber"),
                "Sample message"
).create();

The message is successfully delivered.

But the code does not continue after .create(). Following exception is thrown:

java.lang.NoSuchMethodError: 
com.fasterxml.jackson.datatype.jsr310.deser.JSR310DateTimeDeserializerBase.findFormatOverrides(Lcom/fasterxml/jackson/databind/DeserializationContext;Lcom/fasterxml/jackson/databind/BeanProperty;Ljava/lang/Class;)Lcom/fasterxml/jackson/annotation/JsonFormat$Value;

What I tried

I do not have a pom.xml or build.gradle. I only have web.xml

I have already imported the libraries: twilio-8.9.0-jar-with-dependencies.jar

How can I solve this issue?

The libraries I have:

Libraries

hc_dev
  • 8,389
  • 1
  • 26
  • 38

1 Answers1

1

Twillio SDK, exactly the create() method, seems to depend on Jackson (FasterXML converter library), particularly its module for handling Java8 DateTime (JSR-310). This is obvious when a call of create() results in a NoSuchMethod... for a missing method of class JSR310DateTimeDeserializerBase.

If you would have included the complete error output such as the stack-trace of this exception, then we could have easily seen that.

Analysis

ℹ️ A NoSuchMethod runtime-error is usually not caused by import statements or web.xml. It usually correlates with mismatching dependency-versions.

See the Twilio Java SDK v 8.9.0 (jar) as shown in Maven's web-UI (same as v 8.8.0) includes pom.xml with following dependency:

<dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-jsr310</artifactId>
      <version>${jackson.version}</version>
</dependency>?

and under the properties the required version:

 <jackson.version>2.12.1</jackson.version>

Check dependency versions

Make sure that this jar or package is included within the Twillio jar or at least on your classpath. ⚠️ Also the versions must match (e.g. jackson-core v1 is often depending on jackson-datatype v1). A newer or older version may either change the method (currently not found) i.e. the call or the method-declaration.

Did the method change in Jackson versions?

In previous version (2.11) I also found the method findFormatOverrides with expected signature (parameters and return types) in class JSR310DateTimeDeserializerBase. It was called inside the JsonDeserializer for a Java date-time property. Here when the deserializer is created in context, the parent-class' method is called:

@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {

    JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType());

Solving suggestions

See How do I fix a NoSuchMethodError?. A comment to that question fits yours:

In Netbeans: Right click on project in Projects tab, use "Clean and Build". Solved it for me.

This article on NoSuchMethod is very helpful for this issue.

Use Gradle or Maven

You should consider to use a dependency-management and build-automation tool like Maven or Gradle:

hc_dev
  • 8,389
  • 1
  • 26
  • 38
  • @user15520720 It's nothing to do with `web.xml`. It's about dependencies (classes l in your __classpath__. Is there any __other Jackson jar__ that may interfere (version-wise, e.g. an older version where this method did not exist)❔ – hc_dev Apr 10 '21 at 09:17
  • i think the issue is with i being using ```import java.time.format.DateTimeFormatter;``` – user15520720 Apr 10 '21 at 11:32
  • @user15520720 No, I doubt. This issue is with __conflicting dependencies that clash at runtime__: While Jackson-core (ObjectMapper) tries to deserialize the Twilio API response from JSON to Java-object, deeply in stacktrace, it calls this method and fails with `NoSuchMethodError`. See my updated answer, how I would solve: use Gradle or Maven. ️ – hc_dev Apr 10 '21 at 11:54