简体   繁体   中英

Avalara: Cannot create TransactionModel from TransactionBuilder because of a JSON conversion exception

I am trying to create a TransactionModel object in Avalara, using the TransactionBuilder. I am following the examples in the SDK. The code from the examples, modified for my company, throws a gson.JsonSyntaxException for a DateTime object that Avalara itself controls . I can change the DateTime value, but I have no way to tell it how to format it. This seems like an Avalara bug to me, but I'm hoping that I'm wrong.

Here's my code (NB: same exception whether I use.withDate or not):

 TransactionModel transaction = new TransactionBuilder(client, "COMPANY", DocumentType.SalesOrder, "myCompany.")
.withDate(Calendar.getInstance().getTime())
.withAddress(TransactionAddressType.SingleLocation, null, null, null, null, null, zipCode, "US")
.withLine( new BigDecimal(100.0), new BigDecimal(1), "P0000000")
.Create();

Here's the exception:

com.google.gson.JsonSyntaxException: 2019-10-01
at com.google.gson.DefaultDateTypeAdapter.deserializeToDate(DefaultDateTypeAdapter.java:107)
at com.google.gson.DefaultDateTypeAdapter.deserialize(DefaultDateTypeAdapter.java:82)
at com.google.gson.DefaultDateTypeAdapter.deserialize(DefaultDateTypeAdapter.java:35)
at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.Gson.fromJson(Gson.java:803)
at com.google.gson.Gson.fromJson(Gson.java:768)
at com.google.gson.Gson.fromJson(Gson.java:717)
at net.avalara.avatax.rest.client.serializer.JsonSerializer.DeserializeObject(JsonSerializer.java:15)
at net.avalara.avatax.rest.client.RestCall.call(RestCall.java:99)
at net.avalara.avatax.rest.client.AvaTaxClient.createTransaction(AvaTaxClient.java:19174)
at net.avalara.avatax.rest.client.TransactionBuilder.Create(TransactionBuilder.java:425

Note: I also asked the question at the link below, but I didn't ask the right question, leaving out the part where I couldn't actually change any JSON formats at all: Avalara: What is a "DateTime" valid format for the json date?

Update your pom.xml or equivalent to pull down a more recent version of gson and the problem will go away. See Avalara forums at: https://community.avalara.com/avalara/topics/error-parsing-date-jre-sdk

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.5</version>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM