Skip to content

fix: parse AlarmComment.comment into AlarmCommentJsonNode on deserialization#61

Merged
deaflynx merged 1 commit intothingsboard:devfrom
deaflynx:fix/alarm-comment
Apr 27, 2026
Merged

fix: parse AlarmComment.comment into AlarmCommentJsonNode on deserialization#61
deaflynx merged 1 commit intothingsboard:devfrom
deaflynx:fix/alarm-comment

Conversation

@deaflynx
Copy link
Copy Markdown

Summary

AlarmComment.fromJson now automatically parses the dynamic comment field into a typed AlarmCommentJsonNode, handling both Map (normal) and String (legacy mobile-posted) formats. AlarmComment.toJson properly serializes it back for the API.

Root cause

The mobile app was posting comments as raw strings instead of {"text": "..."} objects. The server stores whatever it receives, so on read the comment field could be either a Map or a String. Since comment is typed as dynamic, any consumer accessing .text or .edited would crash with NoSuchMethodError on the wrong type.

Changes

  • AlarmComment.fromJson — calls _parseComment() to normalize comment into AlarmCommentJsonNode
  • AlarmComment.toJson — serializes AlarmCommentJsonNode back to a Map via .toJson()
  • _parseComment static method — handles MapAlarmCommentJsonNode.fromJson(), String → wraps in AlarmCommentJsonNode(text: ...), other → pass-through

Test plan

  • Deserialize an alarm comment with comment as a JSON object ({"text": "hello"}) — produces AlarmCommentJsonNode
  • Deserialize an alarm comment with comment as a raw string ("hello") — produces AlarmCommentJsonNode with text: "hello"
  • Serialize an AlarmComment with AlarmCommentJsonNode comment — produces correct JSON map
  • Post and update alarm comments via AlarmService — round-trips correctly

…ization

AlarmComment.fromJson now normalizes the dynamic comment field into a
typed AlarmCommentJsonNode for both Map and legacy String formats.
AlarmComment.toJson properly serializes it back for the API.
@deaflynx deaflynx added the bug Something isn't working label Apr 22, 2026
@deaflynx deaflynx requested review from vvlladd28 and removed request for vvlladd28 April 27, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants