Jump to content
borni69

Delphimvcframework and contenttype

Recommended Posts

I have this code

 

procedure THseqScimController.createUser;
 var
    aUser               : TUser;
begin
           aUser := Context.Request.BodyAs<TUser>;
         try
          if  UserScimHandleClass.CreateUser(aUser) then
           begin
             Render(aUser,false);
             Context.Response.StatusCode:=201;
           end
            else
             raise EMVCException.Create(HTTP_STATUS.Conflict,'Conflict');
         finally
           aUser.Free;
         end;
  
End;

It works great from postman with this content type

 application/json

But when request come from Microsoft Azure  it have this  content type

application/sim+json

And it gives  me an error on  

aUser := Context.Request.BodyAs<TUser>;

Body content type not supported…

 

 

Is there a way to change  this  application/sim+json to application/json  or to add application/sim+json  as a supported type ?

 

I guess other option is to parse json and build the object myself 

 

Thanks

Share this post


Link to post

By default DMVC registers a serializer only for the application/json content-type.

But you can define a serializer for other types. In your WebModule, after creating the TMVCEngine add the following code:

FEngine.Serializers.Add('application/sim+json', TMVCJSONDataObjectsSerializer.Create);

 

Share this post


Link to post
On 2/21/2022 at 7:50 PM, João Antônio Duarte said:

By default DMVC registers a serializer only for the application/json content-type.

But you can define a serializer for other types. In your WebModule, after creating the TMVCEngine add the following code:


FEngine.Serializers.Add('application/sim+json', TMVCJSONDataObjectsSerializer.Create);

 

Great Thanks 🙂

Edited by borni69

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×