Base solution for your next web application
Open Closed

AbpController #132


User avatar
0
thomas kristensen created

Hi

First I must say this framework is pretty impressive, a good starting point for any project.

My question is when returning a response in a controller using JSON additional properties are appended to the result as described in the documentation. My problem is I am using a third party client side component that expects another format, so I do not want AbpController to append these additional properties, I just want the raw JSON, how can I do that if I still want AbpController as my bas class?

Thanks a lot.


7 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I think you can solve it with your component. Many components provide an interception point for the request. So, that you can manipulate incoming/outgoing JSON messages in a single point. Try this first.

    If you can not solve it in this way, we may consider to create an extension point for manipulating ABP return values. This feature is requested by some people also.

  • User Avatar
    0
    thomas kristensen created

    Hi

    Yes you are right, it is possible to define the root property on my client control, however:

    ContractResolver = new CamelCasePropertyNamesContractResolver()

    This is an issue, because my server model does not use camelCase, so when sending data to the client control, and the fields have been renamed (case sensitive), it does not work. We should implement a way to custom define if we want to format the response this way, also an option to define if we want result Indented, as this gives overhead when transmitting the data.

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    ABP uses CamelCasePropertyNamesContractResolver since PascalCase is used in C# and camelCase is used in javascript conventionally. We also always use PascalCase DTO properties (in server models) but writing javascript side camelCase. ABP (actually Newtonsoft.Json) handles transformation. I did not understand why this is a problem for you?

    We can not change this behaviour since there are many applications developed upon it. We may provide an option to override behaviour if it's really needed.

  • User Avatar
    0
    thomas kristensen created

    Hi

    The problem is the client side component I use (Telerik) automatic binds to the data in the JSON, and it expects the naming to be as in the model on the server side, which is Pascal. So when the data arrives at the client the component cannot automatically map the data on the client side. As they are all "renamed".

    An option to manually override the naming convention returned in the JSON would be really nice and usefully in this case.

  • User Avatar
    0
    hikalkan created
    Support Team

    OK, now understood your problem. Telerik works generated client side code based on server side.

    Are you using Web API? Only the point here actually: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp.Web.Api/WebApi/AbpWebApiModule.cs#L56">https://github.com/aspnetboilerplate/as ... ule.cs#L56</a> Probably you found it before.

    I don't know how to set JSON serialization options per request or per Web API Controller. I'll check it. Can you create an issue on github? Also, if you find a solution, you can help me.

    Thanks.

  • User Avatar
    0
    thomas kristensen created

    In fact I am using AbpController and returnning JSON: So this line is the problem. A shared place to control it pr. request would be very nice.

    <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp.Web.Mvc/Web/Mvc/Controllers/Results/AbpJsonResult.cs#L60">https://github.com/aspnetboilerplate/as ... ult.cs#L60</a>

  • User Avatar
    0
    thomas kristensen created

    I have just defined an issue on Github for this:

    <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/519">https://github.com/aspnetboilerplate/as ... issues/519</a>