kunal-chowdhury.com

What happens in Java, if we set garbage value to an enum type variable in SOAP Request?



As a developer, everyone knows about the enum type. It is a special data type that enables a variable to be a set of predefined constants, and the variable ought to be identical to one of the values that have been defined for it.

 

In the SOAP web service, the communication is made through XML (string). But what will happen if someone sends a garbage value to an enum type variable in the SOAP request? This post is all about that. So, continue reading it further.

 

What happens if we set garbage value to an enum type variable in SOAP Request?

 

As you know that the enum only holds specific values that were defined at the time of the creation of that enum type. So, it can only hold value, that has been already defined for it.

 

As XML is the only way of communication in SOAP web service, which is actually nothing but a plain string, a consumer can pass any garbage value to it. So, for the enum type variable also, we can pass a string of garbage values to the SOAP request.

 

When the SOAP web service is called by any application, the request XML gets converted to Java objects by marshaling it. If we use Spring-WS Framework, which is one of the implementations of the JAX-WS specification, the @RequestPayLoad annotation will perform the marshaling job for us.

 

While marshaling the request XML to Java objects, if there exists any garbage value for the enum type which is not part of that predefined list of values will be set as NULL by default in Java.

 

 


If you have come this far, it means that you liked what you are reading (What happens in Java, if we set garbage value to an enum type variable in SOAP Request?).

Why not reach little more and connect with me directly on Twitter, Facebook and LinkedIn. I would love to hear your thoughts and opinions.