Skip to content

[5.2] SR-12275: JSONEncoder on Linux can't encode number JSON fragments #2840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ktoso
Copy link

@ktoso ktoso commented Jul 9, 2020

Backport of #2713 to Swift 5.2

Resolves SR-13173 Foundation.JSONEncoder + Swift 5.2.4 + .allowFragments difference between macOS and Linux

Please sanity check @millenomi, I don't think there's a reason to not backport this?
The mac behavior on 2.5.4 is already allowing this, it's just corelibs that doesn't on that version (and it's good since a while now on 5.3).

FYI @drexin

Thanks!

- JSONEncoder now encodes fragments by default to match Darwin.

- JSONDecoder now allows fragments when decoding to match Darwin.

- Update the following TestJSONEncoder tests now that fragments encode,
  these tests now pass on Darwin:

  test_encodingTopLevelSingleValueEnum
  test_encodingTopLevelSingleValueStruct
  test_encodingTopLevelSingleValueClass
@ktoso ktoso changed the title [5.2.5] SR-12275: JSONEncoder on Linux can't encode number JSON fragments [5.2] SR-12275: JSONEncoder on Linux can't encode number JSON fragments Jul 9, 2020
@drexin
Copy link
Contributor

drexin commented Jul 9, 2020

@swift-ci test

@ktoso
Copy link
Author

ktoso commented Jul 9, 2020

Whoops, should have tried locally before pushing, fixing the:

error: type 'JSONSerialization.WritingOptions' has no member 'fragmentsAllowed'

by picking the missing commit.

@ktoso
Copy link
Author

ktoso commented Jul 9, 2020

@swift-ci test

1 similar comment
@drexin
Copy link
Contributor

drexin commented Jul 9, 2020

@swift-ci test

@@ -25,6 +25,8 @@ extension JSONSerialization {

public static let prettyPrinted = WritingOptions(rawValue: 1 << 0)
public static let sortedKeys = WritingOptions(rawValue: 1 << 1)
public static let fragmentsAllowed = WritingOptions(rawValue: 1 << 2)
public static let withoutEscapingSlashes = WritingOptions(rawValue: 1 << 3)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add this in a 5.2 or not since it's public and adding API?

Could we still do this if we make sure no new public types are added?

WDYT @millenomi ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can always add any API that Darwin already has.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(As is the case here.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great to hear, thank you :-)

@drexin
Copy link
Contributor

drexin commented Jul 20, 2020

@swift-ci test macos

@ktoso
Copy link
Author

ktoso commented Jul 21, 2020

Thanks, talked with Mishal and it's not yet going to work, but some time soon. Will ping then :)

@drexin
Copy link
Contributor

drexin commented Jul 24, 2020

@swift-ci test 5.2 macos

1 similar comment
@drexin
Copy link
Contributor

drexin commented Jul 24, 2020

@swift-ci test 5.2 macos

Copy link
Contributor

@drexin drexin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shahmishal shahmishal merged commit 5f7cfd6 into swiftlang:swift-5.2-branch Jul 24, 2020
@ktoso ktoso deleted the wip-cherry-pick-json-fragments branch July 25, 2020 00:35
@ktoso
Copy link
Author

ktoso commented Jul 25, 2020

Wohoo! Thank you @drexin @millenomi @shahmishal

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.

5 participants