I'm trying to send a POST request with RestKit. I have an entity (called workout) that I want to serialize and send to my server backend.
The workout Entity has-one related Entity (called exercise) which has a name.
The Problem I have is that my server expects the JSON in a little bit different format than what RestKit sends:
What the backend receives is the following: exercise[name]. Note that the name attribute of the related entity exercise is in square brackets.
My Server expects these attributes in the following form: exercise.name.
My question is: How can I tell RestKit to use a dot instead of square brackets when serializing entities?
I've looked into setSourceToDestinationKeyTransformationBlock but I could'nt figure out how to use it to solve my problem.
By default RestKit will use form URL encoded serialisation (and that's what it looks like you're getting). To correct this, set the serialisation type to JSON:
objectManager.requestSerializationMIMEType = RKMIMETypeJSON;
Related
What is the realtime use case for serialization in RestAssured?
Even though we can send request body(JSON) as String.
I tried googling but did not get satisfying results.
There are few advantages that come up as your code logic becames more complicated:
You might want to send the same object to different endpoint which might not support json but xml content type. So you can simply have one pojo and RestAssured would take care of all conversions.
Your object might change in runtime. So you will have to introduce changes to your string accordingly. This is quite an error-prone way. Serializer would assure that you send somewhat what is a proper json considering syntax stuff, escaping what needs to be escaped and so on.
There might be the case when you fetch object from one endpoint and send it to another. Hence you would be able to use class for deserialization and further serialization in runtime.
I use Jackson FasterXML product to deserialize JSONs. Now, I noticed in profiler that I got a ton of duplicate strings as a result since every time I receive a JSON it deserialize into an object which always contains some String variable which tells me the Type name. (it's answer to Facebook GraphQL query). Now, naturally, I would prefer for .intern() method to be used during deserialization of this specific method. Is that possible? If so, how?
Seems StringDeserializer can provide whttp://stackoverflow.com/questions/17041249/jackson-override-primitive-type-deserialization
I've just integrated RestKit with a Mac application for communicating with a web service. After much confusion, I have successfully got requests and responses working using it.
The problem I am now finding is that when I want to make a POST request.
I have created a RKRequestDescriptor with a mapping for a whole number of properties and all of the properties are being sent as parameters for the query. I want a way of dynamically changing the parameters that are sent, for example not sending some parameters where the property is nil.
Is this possible as part of the built-in functionality of RestKit? And if so, how?
You would need to use RestKit's Dynamic mapping class to handle mapping at run time.
Dynamic Object Mapping
RestKit supports such use cases via the RKDynamicMapping class.
RKDynamicMapping is a sibling class to RKObjectMapping and can be
added to RKRequestDescriptor and RKResponseDescriptor objects and used
to configure RKMappingOperation instances. RKDynamicMapping allows you
to hook into the mapping process and determine an appropriate concrete
RKObjectMapping to use on a per-object basis.
Or you could not use RestKit and set the POST body yourself. Create the required dictionary by adding only required parameters. Serialize this object with help of NSJSONSerialization and set this NSData object as HTTP Body in the request instance.
Hope developers team wouldn't miss my message. NullValueHandling must be an optional parameter for the JsonFormatter attribute because there are a lot of cases when properties of the object required on client side independently of their value.
And I personally got some troubles trying to identify why my object doesn't have half of it properties.
By the way limitation for DbConext and entity namespace to make the entity observerable on client side is not good too.
Thanks.
Breeze currently sets NullValueHandling to 'Ignore', so as to minimize payloads by not sending any 'null' values. We did not think that this would be an issue because the json serialized objects are materialized into 'breeze' entities on the client and breeze has metadata to determine what the valid properties for each entity are.
What is the use case for actually sending 'nulls' to the client? This is an relatively easy enhancement to make if we have a good use case. The only one that comes to mind is with anonymous objects queried from the server for which metadata will not exist. Is this what you are encountering?
I have a method AddEntity(object o). I am figuring out which entity type it is on the server side using reflection and such and adding it to the database. I am using Self Tracking entities. However this is the error I am getting.
"Element contains data from a type that maps to the name . The deserializer has no knowledge of any type that maps to this name."
This is a lie. I have the entity on the server side, and I have the entity on the client side as a proxy. I am just passing it as an object because I have generalized the AddEntity method.
I am using object because generics are not serializable. So I cannot do something like this:
[OperationContract]
AddObject(T entity)
Any suggestions are most welcome.
No. This is not how the WCF works. WCF serializes entity to wire format and deserializes the entity on the other side. Deserialization process needs to know what type have to be deserialized - such information is not part of serialized data. This type is resolved from operation parameter or return type. Object is not allowed.