shannah / cn1-mirah-json-macros

A Codename One application implementing macros for mapping from JSON to POJO
2 stars 5 forks source link

Allow for extension of stored objects #4

Closed mgroeneweg closed 9 years ago

mgroeneweg commented 9 years ago

I have added new List members to a POJO. The stored data does not have these members. For simple types this is no problem, the value will be the default for the type. However, for a List this causes an exception. Could you please change this to set the list to null when the stored object does not have a value for that member? That would make life a lot easier when extending POJO classes which are used for storage.

Thanks in advance,

Marcel

The stacktrace: [EDT] 0:0:0,10 - Exception: java.lang.NullPointerException - null java.lang.NullPointerException at ca.weblite.codename1.mapper.DataMapper.getList(DataMapper.java:472) at com.itvisors.poc.heijmans.app.mirah.TaskMapper.readMap(/Volumes/Windows VMS/Documents/Shared/NetBeansProjects/mirah_macro_utils/MirahMacroUtils/src/ca/weblite/mirah/utils/DataMapperBuilder.mirah) at ca.weblite.codename1.mapper.DataMapper.readMap(DataMapper.java:719) at ca.weblite.codename1.mapper.DataMapper.getList(DataMapper.java:473) at com.itvisors.poc.heijmans.app.mirah.TaskListStorageDataMapper.readMap(/Volumes/Windows VMS/Documents/Shared/NetBeansProjects/mirah_macro_utils/MirahMacroUtils/src/ca/weblite/mirah/utils/DataMapperBuilder.mirah) at ca.weblite.codename1.mapper.DataMapper.readMap(DataMapper.java:719)

mgroeneweg commented 9 years ago

There is more: When a POJO has a list and that list is never initialized, the object can be written to storage but converting the storage data back to the POJO fails.

shannah commented 9 years ago

Please try replacing your CN1DataTools2.cn1lib with this one https://github.com/shannah/cn1-data-utils/raw/245becd4600d9f18b5b8e37ad997861f028cd2b3/dist/CN1DataTools2.cn1lib (And of course refresh libs). I believe this should fix the issue, but haven't tested it.

mgroeneweg commented 9 years ago

Hi Steve,

Thanks a lot. This fixes the issue where an object with a null list member is read from storage.

Marcel