EJB StatelessBean business method with Object as parameter is becoming null after deseriazation - ejb

Am using EJB Sateless Bean.
in my Bean i have one method which takes 2 parameters, first parameter is Date and the second parameter is an Object, whose syntax is as below.
RemoteINterface rm=homeInterface.create();
rm.method1(date1,mycustomObject);
AT client side am creating myCustomObject and assigned values to its properties .But when the request reaches Server side ,this object is coming as null after deserization.
Here my custom object is implementing serizable interface and it has equals and hashcode method with public default contrutor.But still am getting null.
Any idea what am missing here?

Related

What happens to messages with no matching Listener in Spring-Kafka?

My understanding of the #KafkaListener is that messages are consumed by matching the listener method's argument type with the message type.
What happens to messages that do not have a matching listener?
It's not clear what you mean. What leads you to believe that?
#KafkaListener on a Method means there is a consumer (listener container) for each method so all methods get all records (unless they are in the same consumer group or you assign partitions manually).
#KafkaListener on a Class means you have to annotate multiple methods with #KafkaHandler and the framework will find which handler method to invoke based on the deserialized payload; the value deserializer must be able to deserialize the expected multiple types.
You can designate exactly one #KafkaHandler as the default handler (which is invoked if there is no match) - usually with an Object parameter.
If there is no match and no default handler method, the record goes to the configured ErrorHandler.
The default error handler logs the failure, but you can add your own to do whatever you want.

ErrorBinding Spring portlet MVC

Disclaimer: I wished I had a through understanding before starting working with the framework.
But as it is of now, I'm lacking on that front, and hence the question.
I am working with Spring-Portlet MVC.
I have a flow, where in I take an input on a screen, validate the input, depending upon its result it either render same screen or next screen.
Implementation detail:
I have an action method which takes form backed command object. It checks whether entered input is valid or not. If it is not valid, it populate error message in BindingResult instance it takes as another argument.
We have different render method, to render different screen.
I'm taking command object as an argument in these render method. This command object I'm receiving is same as one passed to action.
Problem:
While rerendering a screen spring-mvc should bind the error message populated in action method. Currently when I take command object as argument in render method spring-mvc is somehow unable to bind that error message. But interesting enough it is able to bind the error message if I don't take command object as argument in render method and rather create a new command object altogether there.
can,some one having better understanding of spring-portlet mvc please explain this behaviour, or tell where I am lacking in understanding.
Regards,
Mawia
EDIT: Just to enrich the below answer: Though I didn't exactly isolated the issue which was causing the said behaviour, but the way I met my requirement was using modelattribute. ModelAttribute can be used either on method or a parameter to a method. It ensures that model will made available to all the call till the view is render(that is my understanding!). So we don't need to take command object as parameter in Render method, just annotate the commandObject parameter in action method with ModelAttribute and then you can get the same object returned from model as suggested in the answer below.
I don't think the command/model object should be an argument/parameter in the render method. I have had the same issue trying to get the validation error messages when command/model is defined as argument in render method signature. I typically have the command/object creation/populate in a separate method, like this:
#ModelAttribute(value="address")
public Address getAddress(#RequestParam Integer id){
Address address = null;
if(id != null){
address = myService.getAddress(id);
}else{
address = new Address();
}
return address;
}
If I still need to access the ModelAttribute/command object from the render method, I typically get it by:
#RenderMapping
public String showAddressPage(ModelMap modelMap){
Address address = modelMap.get("address");
//make any additional changes to address
}
I used this example as reference article

Cannot deserialize an object using a converter?

Given a JSON string of the form {"$type":"MyType, MyAssembly","seed":0"}, why can't JsonConvert.DeserializeObject utilize the JsonConverter associated with "MyType"?
I've tried decorating the MyType class with a [JsonConverter(typeof(MyType))] attribute. Doesn't work. The custom JsonConverter's ReadJson method is never called.
I've tried adding the custom converter to the serializer's settings Converters collection and made sure the CanConvert method returns true for 'MyType' and the CanRead method returns true. Doesn't work. Neither the converter's CanConvert nor its ReadJson method is ever called.
The DeserializeObject method needs to be able to deserialize a JSON string containing an object whose type is unknown at compile time, but whose type is embedded in the JSON object via the special "$type" member. So don't suggest using DeserializeObject<T> or point out that it works for members, whose type is identified in the contract before hand.
FYI, this problem generalizes to cases where the deserialization needs to identify the object type solely from the embedded "$type" member, so for example, it also fails to resolve a converter if the JSON object is in an untyped JSON array, not just at the top-level.
Basically, an object cannot survive a round trip through the serialization/deserialization process, because although the WriteJson method will be called for the Converter when SerializeObject is called, when you subsequently pass the JSON string to DeserializeObject, it fails to call the converter's ReadJson method, and instead constructs an new instance and uses the basic member population routines.

How can I check for a nil="true" value on XML that is passed back from webservice call?

I am receiving xml from a webservice call that contains a nil="true":
<cacheEntry>
<systemFK nil="true"/>
</cacheEntry>
I used the Flex DataService (webservice) wizard to create the service objects for the cacheEntry component. This object will be serialized later on a different webservice call and stored in a database.
I set a breakpoint on the set SystemFK method in the service object. It appears that the value passed in was an empty string!
Allowing this value to be an empty string will cause problems in the webservice implementation in Java on the other side. Since the database value was null it is expecting a null in return, If I avoid setting this value, the serviceObject should send back a null which will make the database happy.
My question is: How can I detect that a nil = true is present in the XML in order to avoid setting this value?
For some reason the ActionScript XML parsers don't know about Booleans. Without seeing the code that got generated for you, my guess is that somehow you're getting the string "true", instead of true, and that's what's causing your problem.
Make changes to the accessors to act as if #nil comes from the XML as a string, and then convert to Boolean manually.

ASP.NET ScriptService prevent return of null properties in JSON

Basically I want to make my script service only serialise properties that are not null on an array of object I am returning... So this..
{"k":"9wjH38dKw823","s":10,"f":null,"l":null,"j":null,"p":null,"z":null,"i":null,"c":null,"m":0,"t":-1,"u":2}
would be
{"k":"9wjH38dKw823","s":10,"m":0,"t":-1,"u":2}
Does anyone know if this is possible?
Basically the reason for this is because null values are for unchanged properties. A local copy is kept in the javascript that is just updated to reduce traffic to the server. Change values are then merged.
You can create a custom JavaScriptConverter class for the JSON serialization process to use to handle your object, and then put the necessary logic in the Serialize method of that class to exclude the properties that are null.
This article has a clear step-by-step discussion of the process involved in creating it.
You probably would not need to actually implement the Deserialize method (can throw a NotImplementedException) if you are not passing that type of object in as an input parameter to your web services.

Resources