This morning I forced caucasian to null (since the Api returned a value at that time). That null
seemed to work, and the null
from the JSON not. It looked as if in that case the oneliner was working properly. That would imply that the JSONPATH is returning a different null
than null
. Strange.
I wrote a test rule that shows this. The logInfo for 2a and 2b fail, but the postUpdate succeed. Both logInfo and postUpdate for 2b and 3b fail.
rule Test
when
Time cron "*/10 * * * * ?" or
System started
then
// sample json with numbers
val rawNumber ='{"result":{"location":"Capelle aan den IJssel","altitude":0,"date":"2017-01-28T16:44:43.452Z","geoLocation":{"geocoding":["Capelle aan den IJssel","ZH","NL"],"lat":"51.91","lng":"4.56"},"uviData":{"uvi":0,"uviMax":0.78,"uviMaxTime":"2017-01-28T11:55:54.462Z"},"uviForecast":[{"date":"2017-01-29T00:00:00.000Z","uviMax":0.89},{"date":"2017-01-31T00:00:00.000Z","uviMax":0.89},{"date":"2017-02-02T00:00:00.000Z","uviMax":0.99},{"date":"2017-02-12T00:00:00.000Z","uviMax":1.31},{"date":"2017-02-27T00:00:00.000Z","uviMax":1.99},{"date":"2017-03-29T00:00:00.000Z","uviMax":4.18}],"sunTime":{"sunrise":"2017-01-28T07:28:35.880Z","sunset":"2017-01-28T16:23:13.044Z"},"burnTime":{"celtic":111,"pale":222,"caucasian":333,"mediterranean":444,"southAfrican":555,"negro":666},"protectionTime":{"protectionFrom":null,"protectionTo":null},"sunAdvice":{"advice":"Use sunscreen with sun protective factor (SPF) 15 or higher, and both UVA and UVB protection"},"weather":{"time":1485621640,"summary":"Overcast","icon":"cloudy","precipIntensity":0,"precipProbability":0,"temperature":6.19,"apparentTemperature":3.03,"dewPoint":1.88,"humidity":0.74,"windSpeed":4.57,"windBearing":196,"visibility":9.99,"cloudCover":1,"pressure":1014.71,"ozone":307.56}}}'
// sample json with null
val rawNull ='{"result":{"location":"Capelle aan den IJssel","altitude":0,"date":"2017-01-28T16:44:43.452Z","geoLocation":{"geocoding":["Capelle aan den IJssel","ZH","NL"],"lat":"51.91","lng":"4.56"},"uviData":{"uvi":0,"uviMax":0.78,"uviMaxTime":"2017-01-28T11:55:54.462Z"},"uviForecast":[{"date":"2017-01-29T00:00:00.000Z","uviMax":0.89},{"date":"2017-01-31T00:00:00.000Z","uviMax":0.89},{"date":"2017-02-02T00:00:00.000Z","uviMax":0.99},{"date":"2017-02-12T00:00:00.000Z","uviMax":1.31},{"date":"2017-02-27T00:00:00.000Z","uviMax":1.99},{"date":"2017-03-29T00:00:00.000Z","uviMax":4.18}],"sunTime":{"sunrise":"2017-01-28T07:28:35.880Z","sunset":"2017-01-28T16:23:13.044Z"},"burnTime":{"celtic":null,"pale":null,"caucasian":null,"mediterranean":null,"southAfrican":null,"negro":null},"protectionTime":{"protectionFrom":null,"protectionTo":null},"sunAdvice":{"advice":"Use sunscreen with sun protective factor (SPF) 15 or higher, and both UVA and UVB protection"},"weather":{"time":1485621640,"summary":"Overcast","icon":"cloudy","precipIntensity":0,"precipProbability":0,"temperature":6.19,"apparentTemperature":3.03,"dewPoint":1.88,"humidity":0.74,"windSpeed":4.57,"windBearing":196,"visibility":9.99,"cloudCover":1,"pressure":1014.71,"ozone":307.56}}}'
val c1 = transform("JSONPATH", "$.result.burnTime.caucasian", rawNumber)
val c2 = null
val c3 = transform("JSONPATH", "$.result.burnTime.caucasian", rawNull)
logInfo("Test", "1")
logInfo("Test", c1)
Weather_Uvi_BurnTimeCaucasian.postUpdate(c1)
logInfo("Test", "2a")
logInfo("Test", if (c2==null) NULL else c2)
Weather_Uvi_BurnTimeCaucasian.postUpdate(if (c2==null) NULL else c2)
logInfo("Test", "3a")
logInfo("Test", if (c3==null) NULL else c3)
Weather_Uvi_BurnTimeCaucasian.postUpdate(if (c3==null) NULL else c3)
logInfo("Test", "2b")
logInfo("Test", c2)
Weather_Uvi_BurnTimeCaucasian.postUpdate(c2)
logInfo("Test", "3b")
logInfo("Test", c3)
Weather_Uvi_BurnTimeCaucasian.postUpdate(c3)
end