-
Notifications
You must be signed in to change notification settings - Fork 178
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
Introducing a general support for native JSON serialization. #194
base: master
Are you sure you want to change the base?
Conversation
This request #209 which implements JsonSerializable. You could have a look at this fork. Deployed on packagist, a new package is now available for PHP7.2+ |
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->toArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also type should be in the json data to make compatible to GeoJSON spec. Better implementation:
public function jsonSerialize()
{
return ['type' => $this->getType(), 'coordinates' => $this->toArray()];
}
@@ -65,6 +65,14 @@ public function toJson() | |||
return json_encode($json); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can replace to:
public function toJson()
{
return json_encode($this);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some comments about GeoJSON compatibility
Here's a rather simple patch that allows spatial data to be json-serialized through native PHP toolset. I am far from being 100% sure this patch covers all use cases, but it does mine (Symfony FOS rest bundle with a JSON content type).