Problem
When trying to set an object in the client side properties by using "Ti.App.Properties.setObject()", the object that contains a key that has a null value it won't be saved.
Actual result
When replacing the 'something' -key with a non-null value, the property however CAN be saved.
Repro sequence
var win = Ti.UI.createWindow({ backgroundColor: 'white' });
var objectWithNullValue = {
expires_at: 1347623585,
value: {
something: null
}
};
var objectWithoutNullValue = {
expires_at: 1347623585,
value: {
something: 'value'
}
};
Ti.App.Properties.setObject('Object1', objectWithNullValue);
Ti.App.Properties.setObject('Object2', objectWithoutNullValue);
Ti.API.info('----- object 1 -----');
Ti.API.info(Ti.App.Properties.getObject('Object1'));
Ti.API.info('Type of Object1: ' + typeof Ti.App.Properties.getObject('Object1'));
Ti.API.info('Value of Object1: ' + Ti.App.Properties.getObject('Object1'));
Ti.API.info('Stringified value of Object1: ' + JSON.stringify(Ti.App.Properties.getObject('Object1')));
Ti.API.info('----- object 2 -----');
Ti.API.info(Ti.App.Properties.getObject('Object2'));
Ti.API.info('Type of Object2: ' + typeof Ti.App.Properties.getObject('Object2'));
Ti.API.info('Value of Object2: ' + Ti.App.Properties.getObject('Object2'));
Ti.API.info('Stringified value of Object2: ' + JSON.stringify(Ti.App.Properties.getObject('Object2')));
win.open();
Ti.API.info('----- My name -----');
Ti.App.Properties.setObject( "object" , { name: "eduardo" , lastName: null } );
Ti.API.info(Ti.App.Properties.getObject('object'));
iOS Console output
[INFO] Detected third-party module: ti.location/1.0
[INFO] Titanium SDK version: 3.0.0 (10/08/12 21:09 7bf73ff)
[INFO] iPhone Device family: universal
[INFO] iPhone SDK version: 5.1
[INFO] iPhone simulated device: iphone
[WARN] The project seems to be having custom info.plist which does not contain the CFBundleShortVersionString
key
[INFO] Generating the missing CFBundleShortVersionString
key
[INFO] Minimum iOS version: 4.0 Linked iOS Version 5.1
[INFO] Launching application in Simulator
[INFO] Launched application in Simulator (5.11 seconds)
[INFO] Application started
[INFO] 1BestPractices/1.0 (3.0.0.v20121008210903.7bf73ff)
[INFO] ----- object 1 -----
[INFO] {
value = {
};
}
[INFO] Type of Object1: object
[INFO] Value of Object1: [object Object]
[INFO] Stringified value of Object1: {"value":{}}
[INFO] ----- object 2 -----
[INFO] {
"expires_at" = 1347623585;
value = {
something = value;
};
}
[INFO] Type of Object2: object
[INFO] Value of Object2: [object Object]
[INFO] Stringified value of Object2: {"expires_at":1347623585,"value":{"something":"value"}}
[INFO] ----- My name -----
2012-10-11 17:12:48.872 1BestPractices[6080:1a903] *** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '{
lastName = "<null>";
name = eduardo;
}' of class '__NSCFDictionary'. Note that dictionaries and arrays in property lists must also contain only property values.
[INFO] <null>
Android Console logs
10-11 17:12:29.501: I/TiApplication(3486): (main) [0,0] checkpoint, app created.
10-11 17:12:29.540: I/TiApplication(3486): (main) [37,37] Titanium 3.0.0 (2012/10/08 21:09 7bf73ff)
10-11 17:12:29.704: I/TiDbHelper(3486): (main) [171,208] No value in database for platform key: 'unique_machine_id' returning supplied default ''
10-11 17:12:29.712: I/TiDbHelper(3486): (main) [4,212] No value in database for platform key: 'hardware_machine_id' returning supplied default ''
10-11 17:12:29.766: I/TiApplication(3486): (main) [58,270] Titanium Javascript runtime: v8
10-11 17:12:29.774: D/dalvikvm(3486): Trying to load lib /data/data/com.appc.test/lib/libstlport_shared.so 0x4051ccb8
10-11 17:12:29.774: D/dalvikvm(3486): Added shared lib /data/data/com.appc.test/lib/libstlport_shared.so 0x4051ccb8
10-11 17:12:29.774: D/dalvikvm(3486): No JNI_OnLoad found in /data/data/com.appc.test/lib/libstlport_shared.so 0x4051ccb8, skipping init
10-11 17:12:29.774: D/dalvikvm(3486): Trying to load lib /data/data/com.appc.test/lib/libkroll-v8.so 0x4051ccb8
10-11 17:12:29.790: D/dalvikvm(3486): Added shared lib /data/data/com.appc.test/lib/libkroll-v8.so 0x4051ccb8
10-11 17:12:29.821: I/TiRootActivity(3486): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
10-11 17:12:29.852: I/TiAnalyticsDb(3486): (main) [35,35] Upgrading Database from 1 to 4
10-11 17:12:30.016: E/TiApplication(3486): (KrollRuntimeThread) [159,194] APP PROXY: ti.modules.titanium.app.AppModule@405e3f90
10-11 17:12:30.094: I/TiAPI(3486): ----- object 1 -----
10-11 17:12:30.094: I/TiAPI(3486): [object Object]
10-11 17:12:30.094: I/TiAPI(3486): Type of Object1: object
10-11 17:12:30.094: I/TiAPI(3486): Value of Object1: [object Object]
10-11 17:12:30.094: I/TiAPI(3486): Stringified value of Object1: {"expires_at":1347623585,"value":{"something":null}}
10-11 17:12:30.094: I/TiAPI(3486): ----- object 2 -----
10-11 17:12:30.094: I/TiAPI(3486): [object Object]
10-11 17:12:30.094: I/TiAPI(3486): Type of Object2: object
10-11 17:12:30.094: I/TiAPI(3486): Value of Object2: [object Object]
10-11 17:12:30.094: I/TiAPI(3486): Stringified value of Object2: {"expires_at":1347623585,"value":{"something":"value"}}
10-11 17:12:30.110: D/LSAPP_TelMon(783): onCellTowerChanged CDMA :: {"NetTyp":"CDMA","BaseStnLat":"2147483647","NetOp":"33404","BaseStnId":"623","BaseStnLng":"2147483647","CntryISO":"mx","NetId":"0","SysId":"24587"}
10-11 17:12:30.126: D/LSAPP_TelMon(783): Telmon : celltower changed...new cell...clear bouncing cells upon new cell and no pending timer
10-11 17:12:30.126: D/LSAPP_TelMon(783): emptyBouncingCells ::
10-11 17:12:30.173: I/TiAPI(3486): ----- My name -----
10-11 17:12:30.180: I/TiAPI(3486): [object Object]
Associated Community thread
http://developer.appcelerator.com/question/139212/sdk-210-propertiessetobject-error-when-setting-null
Can't seem to save it with Ti.App.Properties.setList() either when the object has null values..
@Gijs Nieuwenhuis What is your iOS version? Can you paste an actual sample to test this including your console output? "Ti.App.Properties.setObject()" can save null values as per sample below:
repro sequence
Console output
It's been a week now, closing due to age in no response.
Hi Eduardo, i've been away for a while so I couldn't respond within the required timespan. Anyway, I tested your code and below my console output.
However, I don't really get what you're trying to test with these lines as you are not using the setObject method like it is meant to be used (see http://docs.appcelerator.com/titanium/2.1/index.html#!/api/Titanium.App.Properties-method-setObject) when trying to save the savedObject property in the client side properties. I rewrote the code a bit to show you my problem:
Console output when I execute these lines:
Mijn environment info: * iPhone SDK version: 6.0 * Titanium SDK: 2.1.3 GA As you can see the application doesn't crash, however objects are still not saved when they have null values in them. Please reopen this issue.
Added labels, test case updated & logs appended. Moving to main project to dig into it.
Pull pending https://github.com/appcelerator/titanium_mobile/pull/3523
Ti.App.Properties.setObject can save object with null values in it. Verified on : SDK version: 3.1.0.v20130111163212 CLI version : 3.0.23 OS : MAC OSX 10.7.5 XCode : 4.5.1
Reopening just to update label
Updated label and verified. Tested on: Device: Nexus 7 tab Android Version 4.1 and Simulator 6.0 SDK:3.1.2.v20130619101604 Appcelerator Studio: 3.1.1.201306131423 OS: OSX 10.8 acs:1.0.3 alloy:1.1.3 npm:1.2.14 titanium:3.1.1 titanium-code-processor:1.0.1