Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config.getSection() on JSON file returns com.google.gson.internal.LinkedTreeMap #1757

Open
IAmScRay opened this issue Feb 4, 2021 · 5 comments

Comments

@IAmScRay
Copy link

IAmScRay commented Feb 4, 2021

Expected Behavior

Config.get() returns a ConfigSection object.

Actual Behavior

It returns com.google.gson.internal.LinkedTreeMap instead of ConfigSection -> I can't use methods needed for the plugin.

Steps to Reproduce

  1. Create a "groups.json" in data folder of the plugin with contents provided.
  2. Try to initialise Config & use getSection("groups")
  3. Get an error about class casting.

Crashdump, Backtrace or Other Files

Actual error: https://pastebin.com/5ewcHpXY
groups.json - https://pastebin.com/MBv4c7ZG

Version of Nukkit: Nukkit git-9280804

@IAmScRay
Copy link
Author

IAmScRay commented Feb 4, 2021

I checked the JSON data I used through an online JSON parser - everything works just fine; I even used json_decode() from PHP to check if I missed something in formatting - it simply works.

@IAmScRay IAmScRay closed this as completed Feb 4, 2021
@IAmScRay IAmScRay reopened this Feb 4, 2021
@Sleepybear
Copy link
Collaborator

Sleepybear commented Feb 4, 2021

Config.getSection() would return the ConfigSection. .get() will return a type depending on the type passed as the 2nd parameter, or return an Object that you would have to cast based on knowing your config file.

Did you initialize your config as a JSON file? I know the Config class doesn't work as well with JSON as it does with YAML.

Config groups = new Config("groups.json", Config.JSON);
ConfigSection g = groups.getSection("groups");

Are you doing something like that?

@IAmScRay
Copy link
Author

IAmScRay commented Feb 4, 2021

Config.getSection() would return the ConfigSection. .get() will return a type depending on the type passed as the 2nd parameter, or return an Object that you would have to cast based on knowing your config file.

Did you initialize your config as a JSON file? I know the Config class doesn't work as well with JSON as it does with YAML.

Config groups = new Config("groups.json", Config.JSON);
ConfigSection g = groups.getSection("groups");

Are you doing something like that?

Exactly that. The code in ConfigSection says that it returns new ConfigSection as its result - it just doesn’t in my case.

@IAmScRay
Copy link
Author

IAmScRay commented Feb 4, 2021

This issue is still relevant, although, as @Sleepybear said (and I have switched to it), YAML works much better in such cases than JSON.

@Sleepybear
Copy link
Collaborator

Config class is being removed in Cloudburst, and you will be able to use Jackson directly to parse JSON and YAML, so I doubt this will get fixed unless someone else does a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants