%REM Copyright 2022-2023 HCL America, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License %END REM Option Public Option Declare ' Modify use statement as appropriate for your environent to point to relative path Use "../../../src/VoltScriptJsonConverter" Class HomeData Public timestamp as Double Private enabled as Boolean Public meterLocation as Integer Sub enable() Me.enabled = True End Sub Sub disable() Me.enabled = False End Sub Function isEnabled() as Boolean isEnabled = Me.enabled End Function End Class Class HomeDataSetterConverter as JsonSetterConverter Sub loadParamValuesFromJsonObject(source as JsonObject, converters List as AbstractJsonConverter) If (source.scalarValue = 1) Then Me.forSetter("enable") Else Me.forSetter("disable") End If End Sub End Class Sub Initialize Call sample1() End Sub Sub sample1() Dim helper as New JsonConversionHelper Dim dataConverter as new HomeDataSetterConverter Dim json as String Dim data as HomeData json = |{"enable":1, "timestamp": 1564741004, "meterLocation": 0}| Call helper.withCustomConverter("enable", dataConverter.forSetter("enable")) Set data = helper.fromJsonString(json, "HomeData", "deser-40") Print data.meterLocation & " is enabled? " & data.isEnabled End Sub