Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4105154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:12:34+00:00 2026-05-20T21:12:34+00:00

I am trying to serialize and dederialize an answer from hibernate. almost successfully. First

  • 0

I am trying to serialize and dederialize an answer from hibernate.
almost successfully.
First I get the data (object DealBean) from the DB using

Collections.checkedList(session.createCriteria(DealBean.class).add(Restrictions.eq("account", account)).list(), DealBean.class);

then I serialize it (using gson) and send the result to the client.

in the client I try to deserialize it using

Type type = new TypeToken<Collection<DealBean>>(){}.getType();
    List<DealBean> dealsForAccount = (List<DealBean>)Json.from(SomeAnswerString);

now – I get JsonParseException. I think that the list returned from the hibernate is another type java.util.Collections$CheckedRandomAccessList
I get the following exception (below).
1. any suggestions?
2. am i selecting correctly ? could i cast the result at the server ?

JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@a17378 failed to deserialized json object {“type”:”java.util.Collections$CheckedRandomAccessList”,”content”:”[{\”ID\”:5,\”tradable\”:{\”id\”:5,\”tradableName\”:\”Tradable1\”,\”moneyMultiplier\”:1},\”Action\”:\”buy\”,\”amount\”:501.0,\”price\”:50.3,\”portfolio\”:{\”ID\”:2,\”portfolioName\”:\”Portfolio2\”},\”account\”:{\”ID\”:1,\”accountName\”:\”Account1\”,\”bank\”:{\”ID\”:1,\”BankName\”:\”Bank1\”}},\”date\”:\”12:17:36 02/01/1970\”,\”activitySum\”:0.0,\”aggregated\”:false},{\”ID\”:6,\”tradable\”:{\”id\”:6,\”tradableName\”:\”Tradable1\”,\”moneyMultiplier\”:1},\”Action\”:\”sell\”,\”amount\”:1001.0,\”price\”:50.4,\”portfolio\”:{\”ID\”:2,\”portfolioName\”:\”Portfolio2\”},\”account\”:{\”ID\”:2,\”accountName\”:\”Account2\”,\”bank\”:{\”ID\”:2,\”BankName\”:\”Bank2\”}},\”date\”:\”12:17:36 02/01/1970\”,\”activitySum\”:0.0,\”aggregated\”:false},{\”ID\”:7,\”tradable\”:{\”id\”:7,\”tradableName\”:\”Tradable2\”,\”moneyMultiplier\”:1},\”Action\”:\”buy\”,\”amount\”:502.0,\”price\”:50.5,\”portfolio\”:{\”ID\”:2,\”portfolioName\”:\”Portfolio2\”},\”account\”:{\”ID\”:1,\”accountName\”:\”Account1\”,\”bank\”:{\”ID\”:1,\”BankName\”:\”Bank1\”}},\”date\”:\”12:17:36 02/01/1970\”,\”activitySum\”:0.0,\”aggregated\”:false},{\”ID\”:8,\”tradable\”:{\”id\”:8,\”tradableName\”:\”Tradable2\”,\”moneyMultiplier\”:1},\”Action\”:\”sell\”,\”amount\”:1002.0,\”price\”:50.6,\”portfolio\”:{\”ID\”:2,\”portfolioName\”:\”Portfolio2\”},\”account\”:{\”ID\”:2,\”accountName\”:\”Account2\”,\”bank\”:{\”ID\”:2,\”BankName\”:\”Bank2\”}},\”date\”:\”12:17:36 02/01/1970\”,\”activitySum\”:0.0,\”aggregated\”:false}]”} given the type java.util.Collection
at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:63)
at com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:88)
at com.google.gson.JsonDeserializationVisitor.visitUsingCustomHandler(JsonDeserializationVisitor.java:76)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:98)
at com.google.gson.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:73)
at com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:51)
at com.google.gson.Gson.fromJson(Gson.java:495)
at com.google.gson.Gson.fromJson(Gson.java:444)
at com.google.gson.Gson.fromJson(Gson.java:396)
at positions.server.services.PositionServerServicesInternalWrapperTest.testGetPositionsForPortfolio(PositionServerServicesInternalWrapperTest.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
Caused by: java.lang.IllegalStateException: This is not a JSON Array.
at com.google.gson.JsonElement.getAsJsonArray(JsonElement.java:100)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:468)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:435)
at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:50)
… 31 more

List<BankBean> al = new ArrayList<BankBean>();
al.add(bank1);
al.add(bank2);
String alStr = Json.toWrap(al); // 

List<BankBean> reAl;

Gson gson = new Gson();
Type type = new TypeToken<Collection<BankBean>>(){}.getType();
List<String> listFromJson = gson.fromJson(alStr,type);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:12:35+00:00Added an answer on May 20, 2026 at 9:12 pm

    The type java.util.Collections$CheckedRandomAccessList is a wrapper produced by Collections.checkedList of another list that makes sure that anything added to the list matches the appropriate type signature. Unless you have some way of specifying how to create the backing list and the type (aka instance of java.lang.Class) that it is supposed to check, then there is not enough information to construct one.

    To fix it, maybe change "java.util.Collections$CheckedRandomAccessList" to "java.util.ArrayList" and call Collections.checkedList on the result of your deserialization with the appropriate guard type.

    And to prevent the problem from recurring, maybe do the following before serializing if your list is not an instanceof ArrayList<?>:

    List<Object> mySerializableList = new ArrayList<Object>(myList);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to serialize a MailMessage object using implementation of IXmlSerializable interface. The
I have been trying to serialize some json data in Silverlight. I am using
I'm trying to serialize a Type object in the following way: Type myType =
I am trying to serialize an object to a sql compact database. I am
I had an odd problem today when I was trying to serialize an object.
I'm trying to store an xml serialized object in a cookie, but i get
I'm trying to serialize and deserialize an array list with a object inside: HairBirt
I'm trying to use the new Html helper extension Serialize() from the furthure assembly..
Im trying to get a list of line items to a webpage using JSON,
I've been trying to Serialize and Deserialize BitmapImages. I've been using methods which supposedly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.