Xabier 0 Posted July 7, 2022 Hello, I am testing MARS to consume a XML file in a Post request. I get the following error: Â "Internal server error: [EInvalidCast] Invalid class typecast" Â My definition for the function is similar to one in the example EKON22: Â [POST, Path('recordAge2'),Consumes(TMediaType.APPLICATION_XML), Produces(TMediaType.APPLICATION_JSON)] function WhatsMyAge2([BodyParam] ARecord: TMyRecord): TJSONObject; Â and after watching how MARS creates the xml file (for a GET request) I send in my POST request the following XML (I also specify in Content-Type that is an application/xml): Â <DATAPACKET Version="2.0"> <METADATA> <FIELDS> Â <FIELD attrname="Firstname" fieldtype="string" WIDTH="100" /> Â <FIELD attrname="Lastname" fieldtype="string" WIDTH="100" /> </FIELDS> <PARAMS CHANGE_LOG="1 0 4 2 0 4 3 0 4 4 0 4" /> </METADATA> Â <ROWDATA> Â Â <ROW RowState="4" Firstname="Andrea" Lastname="Magni" /> Â </ROWDATA> </DATAPACKET> Â I have try with different combinations for the XML file but with no success. Â Any help would be appreciated. Â Thanks in advance. Â PD:It is weird to me that instead of "Consumes(TMediaType.APPLICATION_XML)" if I define"APPLICATION_JSON" it accepts the request (the xml content) but it does not map the content of the xml file to a record but no error arises, also if I define the function with NO "Consumes" section and in the body I specify that I will receive a String it also works, so may be the question is if MARS can parse the XML to a record or how it does. (The next question will be how to parse for multiple Firstname, Lastname). Â Share this post Link to post