How do I prevent a field from serialization in a PersistentStateComponent?
Answered
I have a
private volatile ScheduledFuture<?> timerFuture;
in my implementation of PersistentStateComponent and it is saving it out to the xml, but then it can't read it in. I don't need it saved though and if I could stop that, then it would load fine (as it loads fine if I remove timerFuture). I tried:
private transient volatile ScheduledFuture<?> timerFuture;
But that did not prevent it. Is there a way?
Please sign in to leave a comment.
Hi Mark,
Use
@Transient
. See https://plugins.jetbrains.com/docs/intellij/persisting-state-of-components.html#implementing-the-state-classHi Karol Lewandowski ,
I actually tried that, but it seems to have no effect.
I still end up with this in the xml:
```
<option name="timerFuture">
<ScheduledFuture />
</option>
```
It was lombok @Gettter/@Setter on the class instead of the 3 fields I care about.
This line is what helped me figure it out:
https://github.com/JetBrains/intellij-community/blob/master/platform/util/src/com/intellij/util/xmlb/XmlSerializerUtil.java#L17