SpringFox/Jackson doesn't parse JSON attribute - jackson

I'm using Spring boot with springfox and having problems parsing JSON payload from Swagger UI into Java class (JSON->POJO). No errors, but the resulting Java object is missing a field (null). The top class for the class with missing attribute has Mixin to switch datatypes. That part works fine.
I can't really debug since framework does most of the parsing. The req-d attribute is displayed in Swagger under Model Schema correctly. However, when I submit JSON payload containing same attribute, the corresp POJO's attribute is null.
Please steer me to the right direction.

I've figured it out my issue: I was missing setter for the field in the Mixin interface. The JSON was being parsed, but the setter was missing, hence null value.

Related

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

Error casting soap XML to BankData type

Just starting to investigate the Yodlee soap example and I am having problems with an
Unable to cast object of type 'System.Xml.XmlNode[]' to type 'BankData'.
error in the DisplayBankData class. I have tried downloading and creating the Yodlee dll from the wdsl definitions from 2014Q3WSDLs as well as using the DLL that came with the download with no success. The same problem is also happening with the CardData class (and possibly others)
Am I missing something or is there a problem with the wsdl definitions supplied?
After spending many hours trying to work out whats going on here, I have finally worked out that there is something wrong with either the WDSL files generated by Yodlee, or the way that WSDL.exe interprets the WSDL files.
The actual cause of it is because the WSDL does not seem to indicate what type is returned under ItemData1.Accounts, this is because it can be either BankData or CardData, since VisualStudio does not know what type to expect, it de-serialises the object as an XML node.
The way I have managed to get round this is when you use the WSDL.exe to produce the yodleeProxies.vb file, you will need to go into the generated file and then find the defenition for the ItemData1 Class
Partial Public Class ItemData1
You will need to change
Public Property accounts As Object()
to
Public Property accounts As BankData()
Then it knows that the object will be of type BankData
I have also added a new property that expects CardData so that CardData will appear under this one, and will de-serialise correctly
Public Property accounts2 As CardData()
Get
Return Me.accountsField
End Get
Set(value As CardData())
Me.accountsField = value
End Set
End Property
So thats my hack on how to resolve it, if any one else has worked out a more elegant way of getting round this, please do let me know.
I found adding the XmlInclude() attribute below to the ItemData1 class in the proxy file glyn johnston mentioned solves the issue - apparently the deserializer doesn't know to consider ItemAccountData and its descendants when deserializing that property.
I believe 'accounts' should be kept as an array of objects as there are several types that inherit from ItemAccountData including CardData, BankData and others, and upon inspecting the WSDL directly 'accounts' appears to be defined as a 'List' of type 'anyType'.
It is possible it is defined this way to allow for adding newer types in the future without causing de-serialization issues, so basically you need to inspect each element in the array and determine its type individually, ignoring the types you do not know or care about.
...
[System.Xml.Serialization.XmlInclude(typeof(ItemAccountData))]
public partial class ItemData1 {
...
I believe the source of the problem is the Xml deserializer doesn't consider types that aren't somehow tied to the definition of the class ItemData1 via its method signatures, properties etc. and the XmlInclude() is the attribute to use to fix that.

JSON.NET JsonIgnore DeserializeObject

I created a Web API using VS 2012. I have a method with a custom object parameter that I am passing JSON to via Fiddler for testing:
[HttpPost, HttpPut]
public HttpResponseMessage UpsertProject(Projects p)
{
...
}
My Projects object has about a dozen properties marked as JsonIgnore. My assumption was that when my object was serialized into Json those properties would be ignored...which is true. However, when I debug my method I'm noticing that all the object properties marked with JsonIgnore are set to null even if the Json that I pass in from Fiddler is setting them. I also try to get data as Json and deserialize it into a new instance of the object but that also does not set the properties that are marked JsonIngore. I knew JsonIgnore would work for serializing but didn't think it would prevent properties from being set when deserializing. What's frustrating is I know that ScriptIgnore doesn't behave this way, but I want to use JSON.net to handle my serializing/deserializing. I've also created a windows app and tested the same serializing/deserializing functionality and it works in it. So I'm wondering if this is a Web API limitation with the JsonIgnore attribute?
If it works the way you want in the Windows application but not in the Web API, that tells me that the JSON serializer settings are different between the two. What settings are you using in the Windows app that makes it work? You can take those settings and apply them to the Web API serializer in the Register method of the WebApiConfig class (in the App_Start folder of your Web API project). For example:
JsonSerializerSettings jsonSettings = config.Formatters.JsonFormatter.SerializerSettings;
jsonSettings.NullValueHandling = NullValueHandling.Ignore;
jsonSettings.DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate;
...
EDIT
OK, so if I understand you correctly, based on your most recent comments, you want everything to be deserialized if possible, but you only want two specific properties to be serialized and those apparently do not have null or default values. In that case, there are two approaches you can take:
Set the properties that you don't want serialized to null or zero or false (the default value) just before serializing. Because you have DefaultValueHandling set to Ignore, this will cause those properties not to be serialized.
Create several boolean ShouldSerializeXXX() methods in your class where XXX is the name of each property you don't want serialized. These methods should return false. See the first answer of this question for an example.
Don't use JsonIgnore because, as you have seen, this will cause the property to be completely ignored by Json.Net, both for serializing and deserializing.

How do I add a SOAP template from XSD in soapUI when XML extension is in place?

I need to make a large number of SOAP test cases to automate the testing process of an application.
Currently, the architecture requires that a single "generic" SOAP method is invoked with an object of a generic type. Each "real" operation is defined by an element in the generic object and requires an object of an extended type to be used as input.
When I create the request template with soapUI, I only get the generic object elements, but I would like to add the empty template for a specific XSD type that is defined in my current schema to be used.
If I use xsi:type then soapUI correctly says that my markup is not valid against the schema (missing required elements), but I can't manage to get a ready-to-fill XML template.
Can you help me?
Example
genericRequest is made of
<genericRequest>
<methodName>specificMethodName</methodName>
<authenticationID>ABCDEF</authenticationID>
</genericRequest>
sumReuqest (extending genericRequest) for a "sum" operation is made of
<sumRequest>
<methodName>specificMethodName</methodName>
<authenticationID>ABCDEF</authenticationID>
<addend>5</addend>
<addend>3</addend>
</sumRequest>
I would ultimately like soapUI to fill a SOAP template with empty addend item (of course I work with lots of elements, and they are structured too!!)
In this case you need to create two resources in soaupUI one for generic request and other for operation request, I know right now its pain to create each resource for each operation, but soapUI is developed like that or if you think any of the parameters listed : http://www.soapui.org/REST-Testing/understanding-rest-parameters.html could help, you could define parameters as one of the above.
you could try using QUERY or MATRIX style parameters in your resource.