Update PropertiesModel's deserialization of tags to not use Model.initializeFromJson
#1884
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
This updates the tag deserialization logic in
PropertyModel.createModelForProperty
to no longer useModel.initializeFromJson
, which relies on reflection to determine the expected data type. Using reflection is useful when the data model being deserialized is represented by a statically defined class.The problem with using reflections for tags is tag names are dynamic and might be the same as
MapModel
(the statically defined class that holds the tags). Examples:value
,isEmpty
,size
.Since tags must be flat, I updated
PropertyModel.createModelForProperty
to iterate through theJSONObject
key value pairs directly.Additionally, I noticed the reflection logic does not check for a String return value. For completeness, I added that additional case to ensure string properties get string values from the JSON object.
Details
Motivation
#1874
Scope
The intent of this fix is to allow the model deserialization code, which is primarily used during initialization, to successfully deserialize user state.
Testing
Unit testing
Added a new
PropertiesModelTests
to drive and verify deserialization of aPropertiesModel
works as expected regarding tags.Manual testing
Replicated the problem described in this issue by adding a tag named
value
with a non-boolean value. Once added, restart the app and verify proper deserialization.Affected code checklist
Checklist
Overview
Testing
Final pass
This change is