(Possibly solved) Automatic Config Saver parameterized gson cast problem
I have the problem that once I restart MC it can no longer be casted. After indexing its the type Linkedtreemap even though the object is in a List of the type TrustedPartyMember. I had a look around however I was not able to come up with a solution.
Object is created with new row in trustedpartmemberconfig screen using addrow method in there. Saving is with Configmanager .save.
Affected List is List<TrustedPartyMember> in Party Config
It works on init but fails casting after loading using gson later.
code is attached in the Messages below. The Full Code is also available throught the following links.
Full Code links:
TrustedPartyMember.java https://github.com/HacktheTime/BBsentials/blob/hypeswap/common/src/main/java/de/hype/bbsentials/client/common/client/objects/TrustedPartyMember.java
SelectionScreen<T>.java https://github.com/HacktheTime/BBsentials/blob/hypeswap/fabric/src/main/java/de/hype/bbsentials/fabric/screens/SelectionScreen.java
TrustedPartyMemberConfigScreen.java https://github.com/HacktheTime/BBsentials/blob/hypeswap/fabric/src/main/java/de/hype/bbsentials/fabric/screens/TrustedPartyMembersConfigScreen.java
ConfigManager.java https://github.com/HacktheTime/BBsentials/blob/hypeswap/common/src/main/java/de/hype/bbsentials/client/common/config/ConfigManager.java
PartyConfig https://github.com/HacktheTime/BBsentials/blob/hypeswap/common/src/main/java/de/hype/bbsentials/client/common/config/PartyConfig.java
11 Replies
⌛
This post has been reserved for your question.
Hey @Hype_the_Time! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Config Manager
Party Config Simplified
config load code:
save code:
Simp0lefied Screen Code
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
Bump
It would help if you explained why you don't simplify the problem
Wdym
- You have some difficulty with Gson
- You're showing dozens of files involving Minecraft modding
=> what happened so that what you're showing isn't a 10-lines max program trying to use Gson?
The problem with it is that it is integrated into a more or less automated config. Furthermore from the research I did It seems to be a problem with generalised classes. Due too me extending classes at those positions as well and me not knowing what is the source and may be needed I added those things. Those increase the size heavily
I more or less wanted to make sure that all needed info is there
As long as the problem hasn't disappeared, then it is simply factual that all the info is there
It sounds like you have not even tried to play with gson first in the simplest possible case, when you noticed that you didn't get what you want
Working in the simplest case first is simply what you do before doing anything else would cross your mind, at least if you"re serious about programming
I use this config since a while now but i had a different issue somewhere different which caused the problem to only appear now
My research told me its a problem with generalization of classes. The suggested fixes where always things that seemed to be for android with automatically picked up .pro files. I was not able to find a solutions outside of android for default java and mc modding.
I uses dcs like this as second to last step and try to use other sources.
Besides I used it at some different things and server side code too. Both together have right now around 23k lines of code. Not that much but still something.
You seem to suggest a simpler test but I still did not get any ideas on how to fix the problem at all.
I dont know why but now I first try found a stackoverflow post I did not find before.
MyClass object = new Gson().fromJson(new Gson().toJson(((LinkedTreeMap<String, Object>) theLinkedTreeMapObject)), MyClass .class)
Could potentially be a solution to the problem dont know whether its the cleanest solution but could very well work. Ill have a try at it later.
Knowingly not closing it yet until i got it fixed
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.