Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Properties typed
Collection(EnumType)were parsed wrong. For fields whose parser is not a structured type,ODataStructuredTypeFieldParserpassed the whole JSON array to the inner parser in one call:['Red', 'Blue']→undefined(a flags enum gives0)[Color.Red, Color.Blue]→"Ns.Color'Red,Blue'", a single value instead of an arrayUntil 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,serializeandencodenow apply the inner parser to each item. The field'scollectionmetadata decides this.ODataEnumTypeParseris not changed, because it already readsnumber[]as unpacked flags (pack/serialize). Edm parsers already mapped arrays, so they produce the same output as before.Tests
parser.spec.tsdeserialize, serialize (with and withoutstringAsEnum), 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.stringAsEnumrow notes that it applies to each item of an enum collection.