From 541680b95dde73d80dd6a83ed7de911d3df70f1e Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 3 Jun 2026 17:01:17 +0900 Subject: [PATCH] models/word_search: clean up json de/serialization --- lib/models/word_search/word_search_match_span.dart | 5 ++++- lib/models/word_search/word_search_sense.dart | 2 +- lib/models/word_search/word_search_xref_entry.dart | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/models/word_search/word_search_match_span.dart b/lib/models/word_search/word_search_match_span.dart index 58c95e8..a3ac3d9 100644 --- a/lib/models/word_search/word_search_match_span.dart +++ b/lib/models/word_search/word_search_match_span.dart @@ -33,6 +33,7 @@ class WordSearchMatchSpan { Map toJson() => { 'spanType': spanType.toString().split('.').last, 'index': index, + 'subIndex': subIndex, 'start': start, 'end': end, }; @@ -43,12 +44,13 @@ class WordSearchMatchSpan { (e) => e.toString().split('.').last == json['spanType'], ), index: json['index'] as int, + subIndex: json['subIndex'] as int? ?? 0, start: json['start'] as int, end: json['end'] as int, ); @override - int get hashCode => Object.hash(spanType, index, start, end); + int get hashCode => Object.hash(spanType, index, subIndex, start, end); @override bool operator ==(Object other) { @@ -56,6 +58,7 @@ class WordSearchMatchSpan { return other is WordSearchMatchSpan && other.spanType == spanType && other.index == index && + other.subIndex == subIndex && other.start == start && other.end == end; } diff --git a/lib/models/word_search/word_search_sense.dart b/lib/models/word_search/word_search_sense.dart index 7978265..b8bd59d 100644 --- a/lib/models/word_search/word_search_sense.dart +++ b/lib/models/word_search/word_search_sense.dart @@ -81,7 +81,7 @@ class WordSearchSense { 'dialects': dialects.map((e) => e.toJson()).toList(), 'misc': misc.map((e) => e.toJson()).toList(), 'info': info, - 'languageSource': languageSource, + 'languageSource': languageSource.map((e) => e.toJson()).toList(), }; factory WordSearchSense.fromJson(Map json) => diff --git a/lib/models/word_search/word_search_xref_entry.dart b/lib/models/word_search/word_search_xref_entry.dart index 0a1c39c..622dfcb 100644 --- a/lib/models/word_search/word_search_xref_entry.dart +++ b/lib/models/word_search/word_search_xref_entry.dart @@ -16,6 +16,8 @@ class WordSearchXrefEntry { final bool ambiguous; /// The result of the cross-reference, may or may not be included in the query. + /// + /// Be careful not to introduce circular references when using this field. final WordSearchResult? xrefResult; const WordSearchXrefEntry({ @@ -40,6 +42,10 @@ class WordSearchXrefEntry { ambiguous: json['ambiguous'] as bool, baseWord: json['baseWord'] as String, furigana: json['furigana'] as String?, - xrefResult: null, + xrefResult: json['xrefResult'] != null + ? WordSearchResult.fromJson( + Map.from(json['xrefResult'] as Map), + ) + : null, ); }