Persistent data structure not loading properly

Answered

I am trying to persist my own data structure using PersistentStateComponent. The reason why I want to persist this data structure is that I want to save my current state of CheckboxTree between runs. The rough structure of the data I'm trying to save is as follows:

A contains List<B>, B contains List<C> but the items stored in List<C> are only classes that are extended from C and not C itself as its an abstract class (I tried having it as a normal class as well).

The data is stored properly in the XML file which I defined in PersistentStateComponent, but when I try to load it again, all the values stored in List<C> are loaded as null. From what I can see, the problem is that when the data is loaded from the XML file, it sees that the class stored is not of type C, so it loads it as null.

Is there a way to tell the XML deserializer to load those children classes of C as C itself or is there a much better approach to store my data structure?

 

 

0
6 comments

It's impossible to diagnose without access to full sources of your plugin

0

Sorry for not uploading the sources.

Here's the service which extends PersistentStateComponent to store our data structure: TestingChecklist

[REMOVED]

And here's the source for the data structure:

[REMOVED]

which contains a list of classes information

[REMOVED]

which in turn contains a list of methods

[REMOVED]

This (above) is where the problem arises. Since children contains a list of LeafNodes but the data we store are classes extended from the LeafNodes.

 

class of the leaf node:

[REMOVED]

and an example of an extended class

[REMOVED]

 

The XML file stores the data properly but when it's loading the data, it returns null for LeafNode classes

2021-06-02 10:29:00,646 [   7108]   WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object 
2021-06-02 10:29:00,646 [ 7108] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,647 [ 7109] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
2021-06-02 10:29:00,648 [ 7110] WARN - com.intellij.util.xmlb.Binding - Collection PropertyAccessor(name=children, class=com.testbuddy.models.testingChecklist.parentNodes.TestingChecklistMethodNode) contains 'null' object
0

Sorry for being unclear, but I need to see full sources as in access to some repository to load and debug the actual project.

0

Ah sorry for misunderstanding. I'll see if I can make a quick repository where this issue can be duplicated.

0

Hey, here's the repo to duplicate this issue. https://github.com/Teisted/PersistenceSuperClassIssue . I made a small action class that will let you add data to the persisted class. Thank you for taking a look into this issue.

0

If anyone else is facing this issue, I found that @XCollection annotation fixes this issue. You would have to add this annotation above the variable which stores the list of child classes and list all the classes which are stored in the list using elementTypes attribute.

Code example:

data class store(
// children stores a list of childClass objects
@XCollection(elementTypes = [childClass::class])
var children: MutableList<parentClass> = mutableListOf()
)

abstract class parentClass {
// code
}

class childClass : parentClass {
// code
}

 

1

Please sign in to leave a comment.