日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java 不能反序列化_不能将“Java.Lang.Studio”实例反序列化到StaskObl对象令牌中

發布時間:2023/12/4 java 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 不能反序列化_不能将“Java.Lang.Studio”实例反序列化到StaskObl对象令牌中 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我收到下面的錯誤消息,有人能幫助或建議如何最好地調試它嗎?

無法反序列化的實例

java.lang.String

超出起始值的對象

[來源:(pushbackinputstream)處的令牌;行:1,列:37610]

(通過參考鏈:

CopyToList[[產品] ] -gt;java. U.L.AyayList[ 23 ] -&G.M.Mult.產品[“價格”] -& com;COM.價格(“現在”))

我正在嘗試從RESTAPI調用反序列化產品對象。在我添加代碼來反序列化price子類之前,代碼一直工作得很好。如下所示:

"price": {

"was": "",

"then1": "",

"then2": "",

"now": "59.00",

"uom": "",

"currency": "GBP"

},

我的價格POJO如下:

public class Price {

@JsonProperty("was")

String was;

@JsonProperty("then1")

String then1;

@JsonProperty("then2")

String then2;

@JsonProperty("now")

String now;

@JsonProperty("uom")

String uom;

@JsonProperty("currency")

String currency;

public Price() {

//blank constructor for JSON

}

@Override

public String toString() {

return "Price{" +

"was='" + was + '\'' +

", then1='" + then1 + '\'' +

", then2='" + then2 + '\'' +

", now='" + now + '\'' +

", uom='" + uom + '\'' +

", currency='" + currency + '\'' +

'}';

}

}

我編寫了一個JUnit測試來嘗試模擬錯誤,但它在我的測試中有效,

@Test

public void shouldConvertJsonProductListIntoPrice() {

ObjectMapper objectMapper = new ObjectMapper();

String content3 = "{\"products\": [{\"productId\": \"3525085\",\"title\": \"hush Tasha Vest Dress\", " +

"\"price\": {\"was\": \"\",\"then1\": \"\",\"then2\": \"\",\"now\": \"59.00\",\"uom\": \"\",\"currency\": \"GBP\"}, " +

"\"colorSwatches\": [{\"basicColor\": \"Red\",\"skuId\": \"237494589\"},{\"basicColor\": \"Blue\",\"skuId\": \"237494562\"}] " +

"}]}";

JavaType valueType = objectMapper.constructType(ProductList.class);

ProductList readValue;

try {

readValue = objectMapper.readValue(content3, valueType);

assertEquals("3525085", readValue.getProductList().get(0).productId);

assertEquals("hush Tasha Vest Dress", readValue.getProductList().get(0).title);

assertEquals("", readValue.getProductList().get(0).price.then1);

assertEquals("59.00", readValue.getProductList().get(0).price.now);

assertEquals("Blue", readValue.getProductList().get(0).colorSwatches[1].basicColor);

assertEquals("237494562", readValue.getProductList().get(0).colorSwatches[1].skuId);

} catch (Exception e) {

e.printStackTrace();

fail();

}

}

如果我對“now”字段進行注釋,那么我的restapi調用工作得很好,我看不到異常。

所以看起來“now”字段有問題,我注意到它試圖將“59.00”轉換為字符串。這可能是fasterXML轉換器的問題嗎?我需要幫忙嗎?

產品類如下(盡管這是我從API調用中接收到的字段列表減少了很多)。

public class Product {

@JsonProperty("productId")

String productId;

@JsonProperty("title")

String title;

@JsonProperty("colorSwatches")

ColorSwatch [] colorSwatches;

@JsonProperty("price")

Price price;

public Product(){

// blank required for Jackson

}

public Product(String productId, String title, ColorSwatch[] colorSwatches, Price price){

this.productId = productId;

this.title = title;

this.colorSwatches = colorSwatches;

this.price = price;

}

總結

以上是生活随笔為你收集整理的java 不能反序列化_不能将“Java.Lang.Studio”实例反序列化到StaskObl对象令牌中的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。