Skip to content

Parse Collection(EnumType) properties item by item - #110

Merged
diegomvh merged 1 commit into
diegomvh:mainfrom
MrRoundRobin:mrroundrobin-fix-enum-collection-parsing
Oct 16, 2026
Merged

diegomvh merged 1 commit into
diegomvh:mainfrom
MrRoundRobin:mrroundrobin-fix-enum-collection-parsing

Conversation

@MrRoundRobin

Copy link
Copy Markdown
Contributor

Problem

Properties typed Collection(EnumType) were parsed wrong. For fields whose parser is not a structured type, ODataStructuredTypeFieldParser passed the whole JSON array to the inner parser in one call:

  • deserialize ['Red', 'Blue'] → undefined (a flags enum gives 0)
  • serialize [Color.Red, Color.Blue] → "Ns.Color'Red,Blue'", a single value instead of an array

Until now this needed an app-side workaround (withEnumCollectionParsing) that swapped every enum parser for a subclass that accepts arrays. The workaround only fixed deserialization.

OData compliance

CSDL allows Collection(EnumType). OData JSON Format 4.01 §7.1 says enum values are JSON strings (enumValue; flags are comma-separated in a single string), and §7.3 says collections are JSON arrays. So ["Red","Read,Write"] is a valid payload.

Fix

When the field is a collection and the value is an array, ODataStructuredTypeFieldParser.deserialize, serialize and encode now apply the inner parser to each item. The field's collection metadata decides this. ODataEnumTypeParser is not changed, because it already reads number[] as unpacked flags (pack/serialize). Edm parsers already mapped arrays, so they produce the same output as before.

Tests

  • New specs in parser.spec.ts deserialize, serialize (with and without stringAsEnum), round-trip empty arrays and encode collections of regular and flags enums. Without the fix they fail.
  • ng test --watch=false: 860 passed. npm run build: OK.
  • Handbook: stringAsEnum row notes that it applies to each item of an enum collection.

Collection-valued fields with a non-structured parser (e.g. enums) passed
the whole JSON array to the parser, so ['Red','Blue'] deserialized to
undefined (or 0 for flags) and serialized to a single Ns.Type'...' literal.
Map deserialize/serialize/encode over the items when the field is a
collection, per OData JSON Format 7.1/7.3.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@diegomvh
diegomvh merged commit 72262e2 into diegomvh:main Oct 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants