-
Notifications
You must be signed in to change notification settings - Fork 347
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
JSON structure changed between v0.19.2 and v0.20.0 #551
Comments
I have exactly the same 'root' serializer. Seems the $resourceKey is now always an empty string, while until v0.19.2 it was FALSE or NULL. |
Investigated some further: $resourceKey holds the value you can supply as third parameter when calling collection/item methods. While serializing the $resourceKey will be the supplied value if $data contains the root otherwise it will be an empty string. If you adjust the above code to below it will serialize as expected: |
@dwightwatson since the RootSerializer is custom and extending the DataArraySerializer, can you provide more information such as how you are calling so I can try to recreate this on my machine? cc/ @chris-rs |
I'll have re-confirm because it's been a long time since I wrote this code - but I believe the intention was that the root level item in the response was nested under a You can see in my example above you used to be able to get Let me know if that makes sense - alternatively perhaps I can put together a sample repo that demonstrates the break? |
@matthewtrask the serializer works like @dwightwatson describes. I also implemented this years ago. The trick is that we like to add the 'data' value in front of root items and strip it in nested structures. Until v0.19: Since v0.20: Hope this makes sense. |
alright, let me try to write a test to see if the fix I have in mind will work. Will probably be later today for me after work. |
@dwightwatson "alternatively perhaps I can put together a sample repo that demonstrates the break?" do you mind doing this? Even just something simple would be super helpful. im trying to write some breaking tests but not quite getting it to break the way you are describing. Im probably just missing something super obvious but the sample repo would be a huge help if possible. |
Thanks for your patience while I put this together. Here's a pretty basic PHP repro that has distilled the framework code out: https://github.com/dwightwatson/fractal-issue The tests pass on the You can see the only changes in the branches apart from a junit report I accidently committed are:
Hope this helps, please let me know if there is more I can do to help here. |
@dwightwatson this is fantastic, thank you so much for this and thank you both for your patience as I look into this, |
@dwightwatson @chris-rs alright I have a solution. Not super happy with it, but it works. I will write a test in the main library today and cut a 0.20.1 release for yall to have. In fact I think I can just take your test from the example @dwightwatson if that works for you. |
Yeah of course, happy for you to use that code however you need. |
@dwightwatson @chris-rs thank you both for your help and patience. here is the new release that should fix the issue! https://github.com/thephpleague/fractal/releases/tag/0.20.1 |
Looks good to me - thanks so much getting to the bottom of this and shipping a fix! 🤟 |
I've noticed that in upgrading from v0.19.2 to v0.20.0 the output of my JSON responses changed. Reading through the release notes I can't spot what change would have caused this new behaviour so I'm not sure if this is expected behaviour or not. I'm a little confused because the release notes seemed to indicate this was just updates for supported PHP versions.
0.19.2
0.20.0
Note that previously the default included subject and institution were nested directly - now instead they are nested under an "empty" string. I am using a custom serializer which is intended to use
data
for the root level item only.The text was updated successfully, but these errors were encountered: