Replies: 2 comments 1 reply
-
|
I have noticed the same issue. I made a bugreport, but they won't fix it. #42658 |
Beta Was this translation helpful? Give feedback.
-
|
I am having this problem right now. I have basically built the Address value object from the Laravel docs because it fit our use-case perfectly, but when the model is serialized, the value object's We wanted the default serialization to result in a basic string "1234 Test Dr, Dallas, TX 75001", so I added a When the model is serialized, it comes back as JSON: I threw a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm using
Castableclass to cast value objects and I've noticed that, despite having implementedSerializesCastableAttributesinterface in a caster class, whentoArraymethod is called on the model, the casted attribute is not properly serialized (actually it is not serialized at all).Castable class:
Caster class:
Example usage in model:
MyModelis usingEnumerationclass as a casting class which is delegating the casting to theEnumerationCastclass (viacastUsing). Value object set/get works as expected. The issue is with theserializemethod.From what I can tell, in the
HasAttributestrait, there are following methods:As you can see,
isClassSerializableandserializeClassCastableAttributeuse two different methods to check what is the caster class:parseCasterClasswill returnEnumeration(which does not haveserializemethod)resolveCasterClasswill returnEnumerationCastSo,
method_exists($this->parseCasterClass($this->getCasts()[$key]), 'serialize');will return false, thereforeserializemethod inEnumerationCastwon't be invoked.Current implementation forces to add
serializemethod actually to both classes: a castable one and a caster one (sorry, if the naming is kinda awkward). Is that intended behavior?Beta Was this translation helpful? Give feedback.
All reactions