简体   繁体   English

Avalara:由于 JSON 转换异常,无法从 TransactionBuilder 创建 TransactionModel

[英]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.我正在尝试使用 TransactionBuilder 在 Avalara 中创建 TransactionModel object。 I am following the examples in the SDK.我正在关注 SDK 中的示例。 The code from the examples, modified for my company, throws a gson.JsonSyntaxException for a DateTime object that Avalara itself controls .为我的公司修改的示例代码为Avalara 自身控制的 DateTime object 引发了 gson.JsonSyntaxException。 I can change the DateTime value, but I have no way to tell it how to format it.我可以更改 DateTime 值,但我无法告诉它如何格式化。 This seems like an Avalara bug to me, but I'm hoping that I'm wrong.这对我来说似乎是一个 Avalara 错误,但我希望我错了。

Here's my code (NB: same exception whether I use.withDate or not):这是我的代码(注意:无论我是否使用.withDate 都存在相同的异常):

 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?注意:我还在下面的链接中问了这个问题,但我没有问正确的问题,忽略了我根本无法实际更改任何 JSON 格式的部分: Avalara:什么是“日期时间”有效格式json 日期?

Update your pom.xml or equivalent to pull down a more recent version of gson and the problem will go away.更新您的 pom.xml 或等效版本以下载更新版本的 gson 并且问题将 go 消失。 See Avalara forums at: https://community.avalara.com/avalara/topics/error-parsing-date-jre-sdk请参阅 Avalara 论坛: 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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