night-config icon indicating copy to clipboard operation
night-config copied to clipboard

De serializing a Map results in a Null pointer ex

Open NeumimTo opened this issue 5 years ago • 1 comments

class A {
    @Path("a")
    Map<String, String> map;
}
a: {
   "b": "C"
}

throws

java.lang.NullPointerException
	at com.electronwill.nightconfig.core.conversion.ObjectConverter.convertToObject(ObjectConverter.java:202)
	at com.electronwill.nightconfig.core.conversion.ObjectConverter.convertToObject(ObjectConverter.java:239)
	at com.electronwill.nightconfig.core.conversion.ObjectConverter.toObject(ObjectConverter.java:101)
	at com.electronwill.nightconfig.core.conversion.ObjectConverter.toObject(ObjectConverter.java:114)

	while (clazz != Object.class) {
                 .....
		 clazz = clazz.getSuperclass();
         }
 

all java interfaces return null here, but i assume that the bug lies elsewhere, as the library is able to deserialize field with types such as List and Set

NeumimTo avatar Oct 05 '19 09:10 NeumimTo

Collections benefit from a custom logic, Maps aren't handled by ObjectConverter.toObject for now. I'll fix it for the next release. Thanks for reporting!

Meanwhile, you can replace the map by a Config and use its valueMap().

TheElectronWill avatar Oct 05 '19 15:10 TheElectronWill