Open RossOliver opened 11 years ago
@RossOliver maybe take a look at the XML, Yaml and Annotation Drivers. They might give you a clue as to how to disable the discriminator. E.g. I just had to disable it in my XML class
like this in order to fix the error:
<class discriminator-disabled="true"/>
I'm not sure if this is a hack that is working around a design issue I've got, but I don't see why I shouldn't be allowed to have my DB column named (e.g.) type
and at the same time have a serialized type
virtual property.
+1 same issue here
Same here... although commenting out the section in ClassMetadata.php did not help in my case
+1 same issue this time with join table inheritance
Hi All, Any update on this problem? somehow seems to behave strange when tries to deserialise an object that uses inheritance still. Same error message here too
Same issue
So, why this error persists 10 month later?
ping @schmittjoh is this expected behaviour? Experiencing the same issue in the latest release
Seems that the issue is still there.
Ended up implementing a specific behaviour for some Class we had in the project. In our case was just a single limited case so was the quickest solution found.
Good luck
Fryderyk
2014-05-13 22:26 GMT+01:00 James Halsall notifications@github.com:
ping @schmittjoh https://github.com/schmittjoh is this expected behaviour? Experiencing the same issue in the latest release
— Reply to this email directly or view it on GitHubhttps://github.com/schmittjoh/JMSSerializerBundle/issues/299#issuecomment-43015246 .
Thanks for the reply, I've attempted to workaround it in similar ways as the guys mentioned above but I'm using XML configuration which is slightly different. I will post an example later of what I'm trying
The exception throws even on entities that not related to the entities that i serialize. Annotation way @JMS\Discriminator(disabled=true)
+1
Recently I faced same error. What I did is just remove discriminator field from class.
Was:
/**
* @JMS\Discriminator(field="type", map={"foo": "FooRequest", "bar": "BarRequest"})
*/
abstract class BaseRequest {
/**
* THIS ONE CAUSE ERROR
* @JMS\Type("string")
*/
public $type;
}
class FooRequest extends BaseRequest {
/**
* @JMS\Type("string")
*/
public $foo;
}
class BarRequest extends BaseRequest {
/**
* @JMS\Type("string")
*/
public $bar;
}
Become:
/**
* @JMS\Discriminator(field="type", map={"foo": "FooRequest", "bar": "BarRequest"})
*/
abstract class BaseRequest {
}
class FooRequest extends BaseRequest {
/**
* @JMS\Type("string")
*/
public $foo;
}
class BarRequest extends BaseRequest {
/**
* @JMS\Type("string")
*/
public $bar;
}
Hope it will be help somebody )
I think just stumbled here after wondering why I couldn't disable the discriminator field in the output.
1/ The 'disabled' flag for the discriminator is not mentioned in the documentation yet this is a very important bit of the API.
2/ I think there is a good design reason to add this: the discriminator property sole function is to aid later deserialization through JMS. If you are XML output is following a specific XSD schema and is consumed by another application, then discriminator fields are just cruft as they are only internally relevant to the serializing application. Generally, XML parsers should ignore those extra fields, but if you can avoid them in your serialization output: all the better.
FYI I hit it the exception this way using: JMSSerializerBundle + Doctrine Table Inheritance and if you name the doctrine's discriminator-column = "discriminator" :) U'll hit the same exception
In my case I just needed to rename the discriminator-column From: discriminator To: other_value
This is still happening...
+1
+1
+1
+1
+1
It does seem to work if I enable exclusion_policy: all
though.
I'm using the field
so had to set disabled = true
in the discriminator.
Not really sure why, seems a bit unintuitive.
I'm still reproducing the issue and no previous solution is working
I have came across an issue with single table inheritance and serialisation - I get the above error unless I comment out the following code in ClassMetadata.php, after which it works as expected:
I think the exception is thrown because it's checking if the subclass has a property with the name of the discriminator field, which it has to as it subclasses the base-class which defines the field - unless I'm misunderstanding?