Skip to content

v1.3.0

Choose a tag to compare

@passsy passsy released this 13 Oct 15:13
· 2 commits to main since this release
v1.3.0
8e5e866
  • New mapValue for asMap*() and asJsonObject*() parses the values of a map, like the mapper of asList* does for the items of a list #73.
    An error inside a value reports the full location, like adidas.id.

    // {"nike": {"id": "421"}, "adidas": {"id": "532"}}
    Map<String, Shoe> shoes = pick(json).asJsonObjectOrEmpty(mapValue: Shoe.fromPick);
  • New whenNullValue maps the entries with a null value, which mapValue ignores, like whenNull does for lists.

    Map<String, Shoe?> shoes = pick(json).asJsonObjectOrEmpty(
      mapValue: Shoe.fromPick,
      whenNullValue: (pick) => null,
    );
  • New mapKey converts the keys.
    It receives a pick of the key, so the usual parsers work on it.

    // {"421": {"name": "Nike Zoom Fly 3"}}
    Map<int, Shoe> shoes = pick(json).asMapOrEmpty(
      mapKey: (key) => key.asIntOrThrow(),
      mapValue: Shoe.fromPick,
    );

    The keys of asJsonObject*() stay Strings, its mapKey can rename them.
    Use asMap*() to convert the keys to another type.

  • All six parsers are affected: asMapOrThrow(), asMapOrEmpty(), asMapOrNull(), asJsonObjectOrThrow(), asJsonObjectOrEmpty() and asJsonObjectOrNull().
    asJsonObject*() got two type parameters for it, a call without arguments still returns a Map<String, Object?>.

  • New asPlainListOrThrow(), asPlainListOrEmpty() and asPlainListOrNull() return the items of a List as they are, without a mapper #74.
    Declare the item type to get a typed list, an item of another type throws a PickException that names it.

    List<Object?> items = pick(json, 'tags').asPlainListOrEmpty();
    List<String> tags = pick(json, 'tags').asPlainListOrEmpty();