Skip to content

getPresetObject error if an array of presets is posted #58

Description

@carl34

Ran into this error and found a few instances in the forum, for example: https://community.smartthings.com/t/release-cast-web-v1-2-1-chromecast-device-handler-smartapp/88038/1164

It appears to have been introduced when support for an array of media elements was added, I'm not sure if the candidate fix introduces any regressions, but arrays and single media elements are working for me after the code change below.

Test Preset object to cause the error:

{"preset1":[{"mediaTitle":"mp3test","mediaSubtitle":"testing mp3 preset","mediaType":"audio/mp3","mediaUrl":"http://host:3000/test.mp3","mediaStreamType":"LIVE","mediaImageUrl":""}],"preset2":[{"mediaTitle":"Preset 2","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""}],"preset3":[{"mediaTitle":"Preset 3","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""}],"preset4":[{"mediaTitle":"Preset 4","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""}],"preset5":[{"mediaTitle":"Preset 5","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""}],"preset6":[{"mediaTitle":"Preset 6","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""}]}

Error:

error groovy.lang.MissingPropertyException: No such property: mediaTitle for class: org.json.JSONArray @line 352 (getPresetObject)
debug Executing 'playPreset': 1, key: preset1, defaultMediaTitle: Preset 1
debug Executing 'preset1'

A workaround discussed in the forum to avoid the error involved removing the brackets so that arrays aren't used (this is an incomplete workaround though because an array of media elements can't be used):

{"preset1":{"mediaTitle":"mp3test","mediaSubtitle":"testing mp3 preset","mediaType":"audio/mp3","mediaUrl":"http://host:3000/test.mp3","mediaStreamType":"LIVE","mediaImageUrl":""},"preset2":{"mediaTitle":"Preset 2","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""},"preset3":{"mediaTitle":"Preset 3","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""},"preset4":{"mediaTitle":"Preset 4","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""},"preset5":{"mediaTitle":"Preset 5","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""},"preset6":{"mediaTitle":"Preset 6","mediaSubtitle":"","mediaType":"","mediaUrl":"","mediaStreamType":"","mediaImageUrl":""}}

The goal is to find a way to retain the ability to provide an array for each preset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions