我在使用 JMS Serializer 时遇到了一些问题 - 我需要用混合类型的score值反序列化脏 JSON。例如:
{ label: "hello", score: 50 }
Run Code Online (Sandbox Code Playgroud)
或者
{ label: "hello", score: true }
Run Code Online (Sandbox Code Playgroud)
如果我输入@Type("int"),当值是 a 时boolean,它会被反序列化为1or 0...
我想得到100何时值是true,0何时值是false。
我如何在反序列化时管理这种混合类型?
我的课:
class Lorem
{
/**
* @Type("string")
* @SerializedName("label")
* @var string
*/
protected $label;
/**
* @Type("int")
* @SerializedName("score")
* @var int
*/
protected $score;
}
Run Code Online (Sandbox Code Playgroud)