tebru / gson-php

Gson implemented in PHP
Other
151 stars 18 forks source link

Null return type required #10

Closed Samistine closed 6 years ago

Samistine commented 6 years ago

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;
}
natebrunette commented 6 years ago

@Samistine this is happening because gson allows you to pass in an object to deserialize into. In order to handle nested objects, it needs to try to fetch the real object if it exists. I'll look into a way to avoid this if the property is null.

natebrunette commented 6 years ago

Resolved with b27dd775d6f249cdcb7646a963d0f3e695713b54. Tag coming soon.