brick / json-mapper Goto Github PK
View Code? Open in Web Editor NEWMaps JSON data to strongly typed PHP DTOs
License: MIT License
Maps JSON data to strongly typed PHP DTOs
License: MIT License
Hi, Ben
I have used your libraries frequently in the past. I just saw this library. What is the difference between this library and https://github.com/CuyZ/Valinor?
That's something you might add to the README because CuyZ/Valinor has gained quite a traction I reckon.
Thanks for your work :)
What's the best way to map a nested json object?
Imagine this response shown here: https://stytch.com/docs/b2b/api/create-organization
Inside that Json object is an Organisation, which is the only thing I need to map.
Currently, I json_decode the response to test for errors and raise exceptions based on any error object. This means I have access to an organisation object already ($data->organisation).
I don't think re-json_encoding that Organisation object is the way forward, only to pass it to Json-Mapper to do it all again.
So from what I can see, I'm either petitioning for:
Am I seeing this from the wrong angle? All thoughts appreciated!
Edit: similar question, but for when an array of objects is returned.
Edit2: Would it be typical to leave json-mapper alone, and create a PHP object per API Response type?
If you have different props with the matching string in the beginning of their names (and at least two of them are PHPdoc-ed with @param), you get an error at src/Reflection/Reflector.php::149 which is incorrect.
Please, consider adding \W to the end of regular expression at src/Reflection/Reflector.php::149:
$pattern = '/@param(.*)\$' . $parameter->getName() . '\W/';
That class is declared as:
namespace Google\Service\MyBusinessBusinessInformation;
class Location extends \Google\Collection
{
protected $collection_key = 'serviceItems';
protected $adWordsLocationExtensionsType = AdWordsLocationExtensions::class;
protected $adWordsLocationExtensionsDataType = '';
protected $categoriesType = Categories::class;
protected $categoriesDataType = '';
/**
* @var string[]
*/
public $labels;
Class "Brick\Reflection\ImportResolver" not found
row 289 of Reflection/Reflector.php file
private function convertNamedType(string $namedType, bool $isReflection, ReflectionParameter $reflectionParameter): SimpleType|ClassType|EnumType
{
$namedTypeLower = strtolower($namedType);
$isAllowedBuiltinType = in_array($namedTypeLower, self::ALLOWED_BUILTIN_TYPES, true);
$isDisallowedBuiltinType = in_array($namedTypeLower, self::DISALLOWED_BUILTIN_TYPES, true);
$isBuiltinType = $isAllowedBuiltinType || $isDisallowedBuiltinType;
if (! $isBuiltinType && ! $isReflection) {
// Class names coming from reflection are already fully qualified, while class names coming from @param
// must be resolved according to the current namespace & use statements,
$importResolver = new ImportResolver($reflectionParameter); <--- HERE
$namedType = $importResolver->resolve($namedType);
$namedTypeLower = strtolower($namedType);
}
Exceptions such as "Unexpected property %s in JSON data" should display the full path to the property in the JSON document, for easier debugging.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.