by
2
7
3,247
1
Top 1% !
Popular
Famous
Tagged
Easy-to-find
Specified
OpenSource
Popularity: 4101st place

Published on:

Languagejava
LicenseMIT_X11

Equipment class - Example for marshalling/unmarshalling java object using JAX-B

This is the Equipment class. You can see the usage of Jax-B XmlElement and XmlElementWrapper annotations to define xml attributes and wrapper attribute.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/42433/Equipment-class---Example-for-marshallin?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
package com.test.jaxb; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlType; @XmlType(propOrder = {"eqpID", "macAddress", "type", "cards"}) @XmlAccessorType(XmlAccessType.FIELD) public class Equipment implements Serializable { @XmlElement(name = "equipment-ID") private String eqpID; @XmlElement(name = "equipment-type") private String type; @XmlElement(name = "equipment-mac-address") private String macAddress; @XmlElementWrapper(name = "cards") @XmlElement(name = "traffic-card") private List<Card> cards; public Equipment() { } /** * @param eqpID * @param type * @param macAddress */ public Equipment(String eqpID, String type, String macAddress) { super(); this.eqpID = eqpID; this.type = type; this.macAddress = macAddress; } /** * @param eqpID * @param type * @param macAddress * @param cards */ public Equipment(String eqpID, String type, String macAddress, List<Card> cards) { super(); this.eqpID = eqpID; this.type = type; this.macAddress = macAddress; this.cards = cards; } /** * @return the eqpID */ public String getEqpID() { return eqpID; } /** * @param eqpID the eqpID to set */ public void setEqpID(String eqpID) { this.eqpID = eqpID; } /** * @return the type */ public String getType() { return type; } /** * @param type the type to set */ public void setType(String type) { this.type = type; } /** * @return the macAddress */ public String getMacAddress() { return macAddress; } /** * @param macAddress the macAddress to set */ public void setMacAddress(String macAddress) { this.macAddress = macAddress; } /** * @return the cards */ public List<Card> getCards() { return cards; } /** * @param cards the cards to set */ public void setCards(List<Card> cards) { this.cards = cards; } /** * @param card the equipment to add */ public void addCard(Card card) { if (cards == null) { this.cards = new ArrayList(); } cards.add(card); } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "Equipment [eqpID=" + eqpID + ", type=" + type + ", macAddress=" + macAddress + ", cards=" + cards + "]"; } }

Other Steps and Solutions

If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus