I'm developing a simple Symfony 4 application with the JMSSerializerBundle and the RestBundle, which saves data from POST requests and returns data for GET requests. The requests mostly uses JSON as format, but I need one POST route with accepts and parse XML.
I've no problems with all the JSON requests, but the XML one gives me the following error:
(1/1) ClassNotFoundException
Attempted to load class "XmlEncoder" from namespace "Symfony\Component\Serializer\Encoder".
Did you forget a "use" statement for another namespace?
My Configuration for the RestBundle looks like this:
fos_rest:
routing_loader:
default_format: json
include_format: false
param_fetcher_listener: true
body_listener: true
serializer:
serialize_null: true
and the POST method is simply this:
/**
* @Post("/test")
*/
public function postAction(Request $request) {
dump($request); die();
}
I set the Content-Type header of the request to application/xml
. If I cange that to JSON and send an empty body (or one with valid JSON) everything works (I get the dumbed request).
I also tried to add this use
statement: use Symfony\Component\Serializer\Encoder\XmlEncoder;
, but that changes nothing.
Where is my error? Why does the JSON works very well, but the XML gives me errors? Thanks for help!
Edit: The problem doesn't occur, if i remove the Content-Type: application/xml
. But I don't know, why this is the problem and I'm not sure, if the user of the API in the future won't send this specific header. What can I do?