Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Support JsonSerializable annotations (like JsonValue) #377

@Gustl22

Description

@Gustl22

I wonder if one can somehow integrate JsonSerializable into json_dynamic_widget.

Currently (at least in my knowledge) it is quite boilerplaty to write an ArgParser for enums:

https://github.com/peiffer-innovations/json_dynamic_widget/blob/main/packages/json_dynamic_widget/doc/CODE_GENERATOR.md#custom-codecs

  @JsonArgEncoder('borderType')
  static String _encodeBorderType(BorderType value) {
    var result = 'circle';

    switch (value) {
      case BorderType.Circle:
        result = 'circle';
        break;
      case BorderType.Oval:
        result = 'oval';
        break;
      case BorderType.Rect:
        result = 'rect';
        break;
      case BorderType.RRect:
        result = 'rrect';
        break;
    }

    return result;
  }

  @JsonArgDecoder('borderType')
  BorderType _decodeBorderType({
    required value,
  }) {
    var result = BorderType.Circle;

    if (value is String) {
      switch (value) {
        case 'circle':
          result = BorderType.Circle;
          break;

        case 'oval':
          result = BorderType.Oval;
          break;

        case 'rect':
          result = BorderType.Rect;
          break;

        case 'rrect':
          result = BorderType.RRect;
          break;
      }
    }

    return result;
  }

Can't we make use of the @JsonValue annotation of json_serializable, if one defines an enum by themselves?

https://pub.dev/packages/json_serializable#enums

enum BorderType {
  @JsonValue('circle')
  Circle,
  @JsonValue('oval')
  Oval,
  @JsonValue('rect')
  Rect,
  @JsonValue('RRect')
  RRect,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions