apimatic/jsonmapper
apimatic/jsonmapper is a lightweight PHP JSON-to-object mapper for converting API responses into typed models. It maps arrays/JSON to class properties with minimal setup, supports nested structures, and helps keep data hydration consistent across your application.
This release fixes a bug where jsonmapper is unable to deserialize the json to a Child class when the Parent class exists in a different namespace.
This release brings the following improvement in oneof/anyof features:
Now JsonMapper also support checking for a type of any given value in the provided type group, with jsonMapper's method checkTypeGroupFor. Following code sample demonstrate how one can check the type of any value.
$mapper = new JsonMapper();
$value = new Car();
$value = $mapper->checkTypeGroupFor('oneof(Car,Atom)', $value);
Here checkTypeGroupFor will throw a JsonMapperException if value's type didn't exist in the provided type group.
With this release, we have added following:
This release includes a bug fix that may arise while initialization of JsonMapper, if php.ini file is not loaded
This release brings support for mapping oneOf or anyOf between two or more types onto any given value in JsonMapper, it includes following changes:
[@mapsBy](https://github.com/mapsBy) annotation for setters that describes the types that should map the value given for the field name described in [@maps](https://github.com/maps) annotation.[@factory](https://github.com/factory) annotation for setters can now hold the return Type for deserialization method, along with its path.mapFor() which provides mapping for any value by the provided types. It takes value as first argument while the types as second argument.Types must be provided in a specific string format, in both [@mapsBy](https://github.com/mapsBy) and mapFor(). Let A, B are any two types, then:
string, int, Model, float[] or they may also represent a combination of types like, anyOf string and int i.e. anyOf(string,int), or oneOf Car and map of float i.e. oneOf(Car,array<string,float>) etc.Following code snippet explain how to use this feature:
$mapper = new JsonMapper();
$contactOrStringObject = $mapper->mapFor($value, 'oneOf(string,Contact)');
This is how JsonMapper ensures that no other types can be mapped on the provided value but only string or Contact, if value is not one of the given types then mapFor() will throw JsonMapperException.
This release fixes a minor bug in the library which caused warnings when used in exactly PHP 8.0.0 runtime.
Thanks for @mr-feek for submitting PR #9.
This release fixes errors and warnings reported by PHP when JsonMapper was used with PHP >= 8.0.
This release does not add support for new language features introduced in PHP 8. That should be addressed in a later release.
Thanks to @bakerkretzmar and @Dry7 for the PRs #7 and #6.
When mapping a field of array type, the PHP 7 type is too generic. The JsonMapper should have inspected the [@param](https://github.com/param) annotation in the Docblock comment for a hint on what the element type for the array is and used this information to map the array of complex types correctly. However, this was not happening in the case of an array OR nullable type i.e ?array PHP type-hint. Instead, an array of stdClass was being created for an array of complex types.
This release fixes this issue. Just update your JsonMapper version to receive the fix.
[@map](https://github.com/map) and [@factory](https://github.com/factory) annotations to setter methods. Previously, only class fields were supported with these annotations.Since this release changes the mapping behavior for classes that have non-default constructors, we are bumping up by a major version number.
This release fixes warnings reported by PHP when JsonMapper was used with PHP >= 7.0. Other changes include:
Factory Method annotation allows you to specify a method which will be used to initialize a property on the object. This annotation can be applied per property.
Added supported for polymorphic mappings using a discriminator tag.
How can I help you explore Laravel packages today?