Skip to content

Commit f13ad6b

Browse files
authored
fix: Encode id and className properties for nested non-ParseObjects (#177)
1 parent 173e7d8 commit f13ad6b

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
# Parse-Swift Changelog
33

44
### main
5-
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.10.2...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
5+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.10.3...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

8+
### 5.10.3
9+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.10.2...5.10.3), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.10.3/documentation/parseswift)
10+
11+
__Fixes__
12+
* Allow encoding of id and className on nested types that are not ParseObjects ([#176](https://github.com/netreconlab/Parse-Swift/pull/177)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
814
### 5.10.2
915
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.10.1...5.10.2), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.10.2/documentation/parseswift)
1016

Sources/ParseSwift/Coding/ParseEncoder.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,17 @@ public struct ParseEncoder: Sendable {
7272
case custom(Set<String>)
7373

7474
func keys() -> Set<String> {
75-
let defaultObjectKeys = Set(["createdAt",
76-
"updatedAt",
77-
"objectId",
78-
"className",
79-
"emailVerified",
80-
"id",
81-
"score",
82-
"originalData"])
75+
let defaultObjectKeys = Set(
76+
[
77+
"objectId",
78+
"createdAt",
79+
"updatedAt",
80+
"emailVerified",
81+
"score",
82+
"originalData"
83+
]
84+
)
85+
8386
switch self {
8487

8588
case .object:

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "5.10.2"
13+
static let version = "5.10.3"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

Tests/ParseSwiftTests/ParseEncoderTests/ParseEncoderExtraTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import XCTest
1010
@testable import ParseSwift
1111

1212
class ParseEncoderTests: XCTestCase {
13+
14+
struct Dummy: Codable, Hashable {
15+
var id: String
16+
}
17+
1318
struct GameScore: ParseObject, ParseQueryScorable {
1419
// These are required by ParseObject
1520
var objectId: String?
@@ -24,6 +29,7 @@ class ParseEncoderTests: XCTestCase {
2429

2530
// Your own properties
2631
var points: Int
32+
var dummy: Dummy?
2733

2834
// a custom initializer
2935
init() {

Tests/ParseSwiftTests/ParseObjectTests.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import XCTest
1111
@testable import ParseSwift
1212

1313
class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length
14+
15+
struct Dummy: Codable, Hashable {
16+
var id: String
17+
}
18+
1419
struct Level: ParseObject {
1520
var objectId: String?
1621

@@ -43,6 +48,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length
4348
var level: Level?
4449
var levels: [Level]?
4550
var nextLevel: Level?
51+
var dummy: Dummy?
4652

4753
//: custom initializers
4854
init() {}
@@ -348,6 +354,29 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length
348354
XCTAssertTrue(score1.shouldRestoreKey(\.nextLevel, original: score2))
349355
}
350356

357+
func testParseEncoderAllowsIdOnNestedTypesOnParseObject() throws {
358+
var score = GameScore(points: 5)
359+
score.dummy = Dummy(id: "hello")
360+
361+
let object = try ParseCoding
362+
.parseEncoder()
363+
.encode(
364+
score,
365+
acl: nil,
366+
collectChildren: true,
367+
objectsSavedBeforeThisOne: nil,
368+
filesSavedBeforeThisOne: nil
369+
)
370+
let decoded = String(
371+
decoding: object.encoded,
372+
as: UTF8.self
373+
)
374+
XCTAssertEqual(
375+
decoded,
376+
#"{"dummy":{"id":"hello"},"player":"Jen","points":5}"#
377+
)
378+
}
379+
351380
func testParseObjectMutable() throws {
352381
var score = GameScore(points: 19, name: "fire")
353382
XCTAssertEqual(score, score.mergeable)

0 commit comments

Comments
 (0)