Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any XmlIgnoreAttribute or equalvent in java technology

The above are the points taken from this site http://blog.ibeesolutions.com/web-services-implementation-considerations.html

Serialization is an important issue from the web services’ performance point of view since web services uses XML in SOAP messages.

So Reduce Serialization with XmlIgnore

To limit which fields exposed by an object are serialized when the object is passed to or from a Web method and to reduce the amount of data sent over the wire, the XmlIgnore attribute should be used as shown below.

The XmlSerializer class ignores any field annotated with this attribute.

Please note that XmlIgnore serializes only public members unlike the formatters derived from IFormatter interface.

// This is the class that will be serialized.
public class MyClass
{
// The str1 value will be serialized.
public string str1;

/* This field will be ignored when serialized–
unless it’s overridden. */
[XmlIgnoreAttribute]
public string str2;
}

Here the author mentions about the tips on Inproving Webservices and on of them is to use XmlIgnoreAttribute

I have developed a Webservice using Java through Apache CXF Framework .

Please tell me how can I use that or any similar attribute with in Java Technology ??

like image 817
Pawan Avatar asked Dec 22 '22 04:12

Pawan


2 Answers

Web Services implemented using JAX-WS (SOAP) or JAX-RS (RESTful) implementations use JAXB (JSR-222) for the binding layer. When using JAXB you can leverage the @XmlTransient annotation to exclude a field/property from the XML representation.

For More Information

  • http://blog.bdoughan.com/2012/04/jaxb-and-unmapped-properties.html
like image 115
bdoughan Avatar answered Dec 24 '22 01:12

bdoughan


In java properties which shouldnt be serialized are marked as transient or you can implement Externalizable interface instead of Serializable and ignore fields which you don't want to be serialized in your readObject and writeObject method.

like image 28
mprabhat Avatar answered Dec 24 '22 02:12

mprabhat