tebru / gson-php Goto Github PK
View Code? Open in Web Editor NEWGson implemented in PHP
License: Other
Gson implemented in PHP
License: Other
We should look at getters/setters first depending on the direction and properties last unless there's a @Type
annotation.
The order should be
@Type
If I have the follow type declaration @Gson\Type("array<int, string>")
and I read the following JSON {"foo": "bar"}
the JsonDecodeReader
converts the "foo" into null
because "foo" doesn't get wrapped in quotes before it's passed to json_decode()
. This then causes the IntegerTypeAdapter
to not throw an exception, because null is a valid value.
The expected behavior would be to throw an UnexpectedJsonTokenException
.
This is happening because the ArrayTypeAdapter
only checks if $keyType->isString()
when deciding if it should wrap the key name in quotes.
A solution would be to also check if !is_numeric($name)
when deciding to wrap it in quotes. As booleans and null aren't valid keys in PHP or JSON, we don't need extra checks for those.
Hey,
I want to start saying that this looks like a really nice package, it was needed for a long time.
I have a doubt about annotations, since docs are no so clear on how to use it.
I have created a class, which has a single property, and i want to use SerializedName to map the json attribute to the class property:
class User
{
/**
* @SerializedName("id")
*/
protected $userId;
}
I've done several variations of the above code (with \ as first char, with the whole namespace, with the use at the beginning of the class) and all ends on pretty much the same output:
[Semantical Error] The annotation \"@Tebru\\Gson\\Annotation\\SerializedName\" in property User::$userId does not exist, or could not be auto-loaded.
The only two things that worked so far are:
I've seen that AnnotationRegistry is referenced on the tests, is that the actual fix for my problem?
Thanks
I've got a specific use case where I am calculating checksum/hash for the object contents based on the serialization output. Does GSON preserve the order of elements in an associative array?
For instance JSON doesn't support that. I've found many references that GSON maintains that order correctly, however I can't find any official info about that.
Hope you can help to answer that. Thanks !
So I can't seem to get it to deserialize variables that have capital letters in them without specifying the SerializedName annotation.
The following does not work.
/**
* @var integer
*/
public $testTest;
this is a great package ,however if it has a demo ,that's will be vary vary nice
Fatal error: Interface 'Psr\SimpleCache\CacheInterface' not found in /Users/ericmills/MailControl/tracking-api/vendor/symfony/cache/Simple/ArrayCache.php on line 28
deprecated SimpleCacheAdapter, use Psr16Adapter instead. This is withing symfony/cache 4.3.0 it was deprecated.
https://github.com/symfony/cache/blob/master/CHANGELOG.md
Look into falling through to looking at default property values as well.
As title, since the Travis CI building is very slow, I think it's time to migrate to the GitHub actions.
Once this issue has been accepted by repository owner, I will be happy to work on that.
If a global class existing with the same name as the short name in a docblock, the global gets used instead.
The TypeTokenFactory
could be fixed and enhanced to support PHP typed properties.
The following currently throws an exception if it encounters a non-initialized typed property:
$property->getDeclaringClass()->getDefaultProperties()[$property->getName()];
See https://3v4l.org/gVdKO to illustrate why this happens.
An easy fix would be to add ?? null
to the end.
Somewhere in this chain of guessing the property's type could be a check for the property type:
$propertyAsTyped = $property->getType()->getName();
Obviously it would need a PHP version check around execution, and a null check in case it's not typed.
On getter functions I have to allow nulls in the type declaration ?MySpecialClass. I tried specifying the type using annotations but the getter still gets called before there is data in the variable it's calling.
/**
* @return string
*/
public function getNumber(): ?string
{
return $this->number;
}
I would like to do this
/**
* @return string
*/
public function getNumber(): string
{
return $this->number;
}
this is a great package ,however if it has a demo ,that's will be vary vary nice
For example, name could be stored as first and last name in a model, but serialized as name
.
I know it's an early work, but it would be nice to have some examples on how to use this package.
This will allow reusing classes that are hydrated with data in one format, but wish to serialize it in another.
I'm trying to use gson-php: 0.7.1 and I'm receiving this error due to __toString is deprecated as of php 7.1
this error is thrown in TypeTokenFactory in line 98
$setterType = TypeToken::create((string)$parameter->getType());
though instead of casting to string getName()
should be called.
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.