Skip to content

Releases: apimatic/jsonmapper

Support for checking type of a value in a oneof/anyof type group

13 Jun 10:08
99fc537
Compare
Choose a tag to compare

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.

Support of strict types for models inside oneof/anyof cases

30 May 10:26
5b8386c
Compare
Choose a tag to compare

With this release, we have added following:

  • Support added for strict type checking in model's fields inside any oneof/anyof cases.
  • Refactored JsonMapperException class to hold all relevant exceptions that can be thrown by the library at one place.
  • Refactored TypeCombination class to increase the performance of the library.

Php ini file loading bug fix

25 May 07:27
12e32ca
Compare
Choose a tag to compare

This release includes a bug fix that may arise while initialization of JsonMapper, if php.ini file is not loaded

Adds check for disabled comments in JsonMapper.

23 May 08:01
731ecf2
Compare
Choose a tag to compare
  • Throw a JsonMapperException if PHP configuration discards comments, by some setting in the configuration file or locally.
  • Add tests related to the changes.
  • Enable tests in .yml file for PHP 8.1 and compatibility changes.

OneOf and AnyOf Support

16 Feb 07:56
9a2ceb1
Compare
Choose a tag to compare

This release brings support for mapping oneOf or anyOf between two or more types onto any given value in JsonMapper, it includes following changes:

  1. Addition of @mapsBy annotation for setters that describes the types that should map the value given for the field name described in @maps annotation.
  2. @factory annotation for setters can now hold the return Type for deserialization method, along with its path.
  3. Addition of public method 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 and mapFor(). Let A, B are any two types, then:

  • oneOf(A,B) represents either A or B not both.
  • anyOf(A,B) represents either A, B or both.
  • oneOf(A,B)[] represents an array where an element can either be A or B not both
  • anyOf(A,B)[] represents an array where an element can either be A, B or both.
  • array<string,oneOf(A,B)> represents a map where an element can either be A or B not both.
  • array<string,anyOf(A,B)> represents a map where an element can either be A, B or both.
  • In all the above formats A or B might represent a simple type like 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.

Bug Fix for PHP 8.0.0

16 Jul 09:11
f7588f1
Compare
Choose a tag to compare

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.

Compatbility Fixes for PHP 8

09 Feb 06:05
Compare
Choose a tag to compare

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.

Contributors

Thanks to @bakerkretzmar and @Dry7 for the PRs #7 and #6.

Fixes Bug During Mapping of Array Types

18 Jul 12:25
Compare
Choose a tag to compare

When mapping a field of array type, the PHP 7 type is too generic. The JsonMapper should have inspected the @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.

Adds Support for Non-Default Constructors for Mapping and Other Features

12 May 20:28
Compare
Choose a tag to compare
  1. Adds support for mapping to classes that have non-default constructors. Arguments are passed to the ctor based on the parameter name and type and matching setter.
  2. Adds support for @map and @factory annotations to setter methods. Previously, only class fields were supported with these annotations.
  3. Improves test coverage by adding new unit tests.

Since this release changes the mapping behavior for classes that have non-default constructors, we are bumping up by a major version number.

Compatibility Fixes for PHP 7

06 Apr 21:06
0883d38
Compare
Choose a tag to compare

This release fixes warnings reported by PHP when JsonMapper was used with PHP >= 7.0. Other changes include:

  • Dropped support for legacy PHP versions 5.4 and 5.5 and HHVM. JsonMapper might work with these versions but we no longer test with them.
  • Some warnings reported by PHP 7.* when running PHPUnit and PHP Code Sniffer were fixed by updating versions.