Skip to content

[ObjectMapper] added earlier skip to allow if=false when using source mapping #60491

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
merged 1 commit into from
May 20, 2025

Conversation

maciekpaprocki
Copy link
Contributor

@maciekpaprocki maciekpaprocki commented May 20, 2025

Q A
Branch? 7.3
Bug fix? yes
New feature? no
Deprecations? no
License MIT

Currently when using object mapper from source if seems to fail if the oiginal source class doesn't have this field.

Which means

class A {
   public $id = 1
} 
class B {
  #[Map(source:'id')]
  public $id = null
  #[Map(if:false)]
  public $additionalInfo = null
}
$objectMapper->map(new A(), new B());

will fail because there's no property available in A.

Moving the if statement up in the object mapper solves the issue if #Map(if: false). It doesn't support full "IF" logic as it's dependent on value, but I think that's all right. Don't really see why someone would need that if there's no mapping value either way.

@maciekpaprocki
Copy link
Contributor Author

Hey!

Thanks for your PR. You are targeting branch "7.3" but it seems your PR description refers to branch "7.3 bug fix". Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

Sorry bot, misspelling :)

also, for whover is reviewing. I didn't add changelog as i think object mapper for now on is in preview. Please let me know if you would like me to add that.

@carsonbot carsonbot changed the title added earlier skip to allow if=false when using source mapping [ObjectMapper] added earlier skip to allow if=false when using source mapping May 20, 2025
@symfony symfony deleted a comment from carsonbot May 20, 2025
@symfony symfony deleted a comment from carsonbot May 20, 2025
@soyuka
Copy link
Contributor

soyuka commented May 20, 2025

@maciekpaprocki thanks I agree with the patch, changelog is not needed as its for features only if I'm not mistaken.

@nicolas-grekas
Copy link
Member

Thank you @maciekpaprocki.

@nicolas-grekas nicolas-grekas merged commit d4fd462 into symfony:7.3 May 20, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants