Why do we need to use POJO class and serialization in RestAssured, when we can directly send request body in the form of String? - api

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.

Related

Is there a way to get raw message from MassTransit?

I have a consumer with generic argument IEvent. This type is a base interface for all messages, and child interfaces of IEvent have some other properties. I'd like to have access to the raw message with all properties of nested types instead of only IEvent scope. These properties can be seen through RMQ admin dashboard and I think there should be a way to put them out.
You could use context.TryGetMessage<T>() to request the specific type, which essentially attempts to deserialize the message into the specified type (as long as it is in the list of messageTypes serialized into the header).
Otherwise, you can use context.TryGetMessage<JToken>(), and get the JToken from JSON.NET, which can be used to navigate the message body.
Honestly, this isn't the best approach to properly handling events, etc., so I'd refer to the documentation to see how to properly consume the various message types (and let MassTransit do the hard work).

fasterxml jackson JSON deserialization - custom adding

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

Getting SOAP request as POJO in Mule

In our project we expose a number of web-services that were generated from a wsdl. After generating them, I can see that the requests and responses are mapped to POJOs and when I am making the response, I just set a new POJO. This works really nice. However, I have a problem with the request. When we receive the request I expected that the payload will be a POJO mapping the parameters from the request. The payload becomes actually an array of objects. I can access the values but this is not very comfortable. You can take a look at the picture.
I can see that the under "Variables" in the method it is correctly matched to the POJO we would like to have. Is there some setting that I am missing somewhere so that we can get the payload to be mapped to correct POJO type?
Re-run the WSDL to Java codegen but this time with wrapper style disabled, see: https://cxf.apache.org/docs/wsdl-to-java.html#WSDLtoJava-wrapperstyle

How to get the value from MessageHeaderInfo

I am sending some SOAP headers to a WCF service and I am trying to catch them using behavior extension.
When the message is received I am going through its headers collection.
Each header is of MessageHeaderInfo type which does not have a value property.
How can I extract the value? It can be done with an ugly parsing (to remove the xml elements around the value) but it feels lame.
your help is most appriciated!
The way you normally use message headers is by defining a DataContract (or an XmlSerializable class) to represent your header, then use Message.Headers.GetHeader<T>() to retrieve it. That method will do the deserialization and hand you a strongly typed object you can use.

Use XmlSerializer on request and DataContractSerializer on response?

Is it possible to receive a request with attributes and use the XmlSerializer to deserialize it and send a response back with just elements using the DataContractSerializer?
Also, if you receive a request with attributes, must you use the XmlSerializer to deserialize the content?
For the second question: if you have attributes, then you need to use the XmlSerializer - the DataContractSerializer doesn't support them.
For the first question: yes, it's possible. No, it's not easy. The selection of the serializer is done at the operation formatter level. WCF allows you to change the serializer per operation by using the [XmlSerializerFormat] or [DataContractFormat] (which is default), but that will bind the serializer to both request and responses.
If you really, really want to do it, you can create your own formatter (replace it using some operation behavior), then in that formatter you can choose how you serialize / deserialize the inputs / outputs (you can even use different serializers for each parameter), but you'll need to create one formatter, which isn't something too easy to do.
I've written some posts about message formatters and replacing serializers in Silverlight which can give you a hint on how to start about it. But if you can live with XmlSerializer only, that'll be a lot easier.