smartystreets / smartystreets-java-sdk

The official client libraries for accessing SmartyStreets APIs from Java (and JRE-based languages)
https://smartystreets.com/docs/sdk/java
14 stars 18 forks source link

Error with client.send() when using R8 #53

Open tommyjackson opened 2 months ago

tommyjackson commented 2 months ago

We use the smartystreets SDK in our Android app, but are noticing the following issue when the app is built obfuscated with R8 and tries to invoke client.send(lookup):

Non-fatal Exception: jd.b: Cannot construct instance of `di.a` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 2] (through reference chain: java.lang.Object[][0])
       at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.<init>(InvalidDefinitionException.java:30)
       at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
       at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1887)
       at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:414)
       at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1375)
       at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:274)
       at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:218)
       at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
       at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4905)
       at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3909)
       at com.smartystreets.api.SmartySerializer.deserialize(SmartySerializer.java:23)
       at com.smartystreets.api.us_street.Client.send(Client.java:51)
       at com.smartystreets.api.us_street.Client.send(Client.java:27)

We can remedy this locally by adding the following keep rule to our proguard-rules.pro:

-keep class com.smartystreets.api.** { *; }

but it isn't an ideal solution, as 3rd party libraries should include their own consumer-rules.pro that specify what specific files need to be kept so we don't have to end up keeping an entire library.

RyanLCox1 commented 2 months ago

Thank you for submitting an issue. We'll look into this.