models/word_search: clean up json de/serialization

This commit is contained in:
2026-06-03 17:01:17 +09:00
parent 505380d2cc
commit 541680b95d
3 changed files with 12 additions and 3 deletions
@@ -33,6 +33,7 @@ class WordSearchMatchSpan {
Map<String, Object?> 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;
}
@@ -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<String, dynamic> json) =>
@@ -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<String, dynamic>.from(json['xrefResult'] as Map),
)
: null,
);
}