How to avoid public int field from JAXB serialization?

How can I avoid field serialization? I am using xml attributes. Currently the field does not have an attribute, but falls into xml ...

+4
source share
2 answers

Annotate the field you want to exclude using @XmlTransient .

+8
source

Option # 1 - Change Access Type

By default, the JAXB implementation (JSR-222) will handle all public fields and properties. If you want to limit this to only public properties, you can do the following:

 @XmlAccessorType(XmlAccessType.PROPERTY) public class Foo { public int bar; // Not considered mapped if access type is set to PROPERTY } 

Option number 2 - indicate that the field is not displayed

You can mark the field / property with @XmlTransient so that it does not display.

 public class Foo { @XmlTransient public int bar; // Not considered mapped } 
+4
source

Source: https://habr.com/ru/post/1434577/


All Articles