Skip to content

Comments

Added new parse to dictionary nullable#17

Closed
Paulohos wants to merge 2 commits intothejohnlima:mainfrom
Paulohos:feat/parse_nullable_object
Closed

Added new parse to dictionary nullable#17
Paulohos wants to merge 2 commits intothejohnlima:mainfrom
Paulohos:feat/parse_nullable_object

Conversation

@Paulohos
Copy link

No description provided.

@thejohnlima thejohnlima self-requested a review June 17, 2025 13:22
@thejohnlima thejohnlima added this to the 1.0.9 milestone Jun 17, 2025
@sonarqubecloud
Copy link

}

/// Returns an optional `LMJSONOptional` if the serialization is successful; otherwise, returns `nil`.
public func dictionaryNullable() -> LMJSONOptional? {
Copy link
Owner

Choose a reason for hiding this comment

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

Please fix code indentation

}

/// Returns an optional `LMJSONOptional` if the serialization is successful; otherwise, returns `nil`.
public func dictionaryNullable() -> LMJSONOptional? {
Copy link
Owner

Choose a reason for hiding this comment

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

Would be better to declare this function after the dictionary() one:

Screenshot 2025-06-17 at 11 09 25 AM

XCTAssertEqual(movies.last?.title, "Iron Man")
}

func testParseNullable() {
Copy link
Owner

Choose a reason for hiding this comment

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

This project uses 2 for tab and indent, so it needs to adjust the code indentation accordingly.

Screenshot 2025-06-17 at 11 11 25 AM


@testable import LMStorage

struct ContentId: LMCodable {
Copy link
Owner

Choose a reason for hiding this comment

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

Would be better to simplify this model this way:

struct Media: LMCodable {
  var id: String?
  var source: String?
}


func testParseNullable() {
let contet = ContentId(id: "Movie-ID", seriesTmdb: nil, source: "Amazon Prime")
let dict = contet.dictionaryNullable()
Copy link
Owner

Choose a reason for hiding this comment

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

@Paulohos I think this PR won't be required, you can use the double optional for the property you want to be encoded, even if it's null as described here.

Example:

Screenshot 2025-06-17 at 12 44 40 PM Screenshot 2025-06-17 at 12 44 23 PM

Copy link
Owner

Choose a reason for hiding this comment

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

Please let me know if it works for you

Copy link
Owner

Choose a reason for hiding this comment

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

If it works, we can still keep the PR to add the unit test to cover this scenario

@Paulohos Paulohos closed this Jun 17, 2025
@thejohnlima thejohnlima removed this from the 1.0.9 milestone Jan 15, 2026
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