toJson method

  1. @override
DynamicMap toJson()
override

Implementation

@override
DynamicMap toJson() {
  final DynamicMap map = <String, dynamic>{};
  if (should != null && must == null) {
    map.addAll(
      <String, dynamic>{
        'bool': <String, List<DynamicMap>>{
          'should':
              should!.map((QueryClause match) => match.toJson()).toList(),
        },
      },
    );
  } else if (should == null && must != null) {
    map.addAll(
      <String, dynamic>{
        'bool': <String, List<DynamicMap>>{
          'must': must!.map((QueryClause match) => match.toJson()).toList(),
        },
      },
    );
  } else {
    final List<DynamicMap> mustList =
        must!.map((QueryClause match) => match.toJson()).toList();
    map.addAll(
      <String, dynamic>{
        'bool': <String, List<DynamicMap>>{
          'must': mustList
            ..add(
              <String, DynamicMap>{
                'bool': <String, dynamic>{
                  'should': should!
                      .map((QueryClause match) => match.toJson())
                      .toList(),
                },
              },
            ),
        },
      },
    );
  }
  return map;
}