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

  • SEARCH
  • Home
  • 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 7576791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:00:32+00:00 2026-05-30T17:00:32+00:00

I´m having some problems when i try to deserializing a Java class. My classes

  • 0

I´m having some problems when i try to deserializing a Java class.
My classes are :

Abstract Class A {
Long ID
String name 
...
}
Class B extends A{ 
String Type
String Value
}
Class C extends A{
List<A> typedList;
}

And my Serialization/Deseralization Methods:

public String serialize(T object) {
        String returnValue = "";

        try {
            returnValue = mapper.writeValueAsString(object);

        } catch (JsonGenerationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.println(returnValue);
        return returnValue;
    }

public List<T> unserialize(String data, Class<?> clazz) {
        List<T> returnValue = new LinkedList<T>();
        //JavaType topMost = mapper.getTypeFactory().constructParametricType(MyWrapper.class, ActualClassRuntime.class); 
        try {

            returnValue = (List<T>) mapper.readValue(data,clazz);
        } catch (JsonParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return returnValue;
    }

The list inside the C class contain B and C elements. Serialization is done without problems but when i tried to deserialize C , Jackson can´t rebuild my typedList correctly.
It uses LinkedHashMap instead of LinkedList and don´t use the correct types.
Any ideias how to solve this ?
Thanks in advance!

  • 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-30T17:00:33+00:00Added an answer on May 30, 2026 at 5:00 pm

    If you expect to get a List, you must pass a List type: here you are giving type of clazz but expect type of List<T>. This won’t work, even if clazz is of type List.
    So you need to pass proper type. But for List (and Map) types, you further need to specify contents type: and type variable does not do. What works is something like:

    List<MyType> list = mapper.readValue(jsonSource, new TypeReference<List<MyType>>() { });
    

    where TypeReference must be used due to Java type erasure.

    You can also construct structured types from components dynamically, if they are passed as arguments:

    Class<?> elem = ...;
    List<?> list = mapper.readValue(jsonSource,
      mapper.getTypeFactory().constructCollectionType(ArrayList.class, elem);
    

    The reason you get LinkedHashMap is just because of missing type information: if JSON Object is encountered, and requested type is java.lang.Object (as would be the case if you just passed type List.class to bind to), this is the type that would be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having some problems parsing a string to a textbox type, im using the
I am using the jQuery UI components but having some problems. If I try
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
Thanks for the help below, however, I'm still having some problems, I'll try and
I am having some problems updating to the right value. On the page which
I'm having some problems when i try to compile my sample C++ project, i'm
I'm having some problems running a LINQ query off of a LINQ2SQL class that
I am having some problems when i try to validate the user input from
I have a class that is having some dependency problems referencing external library files.
I'm having some problems tracing the reason that I can't load a java(fx) applet.

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.