Skip to content

Commit

Permalink
Write getters with JAX Annotations by hand
Browse files Browse the repository at this point in the history
There seems to be a problem with the onX feature from lombok in JDK8. See projectlombok/lombok#778.
  • Loading branch information
JLengenfeld committed Mar 22, 2016
1 parent e524bc3 commit d4b68cd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
19 changes: 15 additions & 4 deletions src/main/java/de/flux/playground/deckcompare/dto/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

@Data
@EqualsAndHashCode(exclude = { "quantity" })
Expand All @@ -18,16 +17,28 @@ public class Card {
private static final int MIN_QUANTITY = 1;
private static final int MAX_QUANTITY = 3;

@Getter(onMethod = @__(@XmlAttribute(name = "qty")) )
private int quantity = 0;
@Getter(onMethod = @__(@XmlAttribute) )
private String id = null;
@Getter(onMethod = @__(@XmlValue) )
private String value = null;

public void setQuantity(int quantity) {
Validate.inclusiveBetween(MIN_QUANTITY, MAX_QUANTITY, quantity);
this.quantity = quantity;
}

@XmlAttribute(name = "qty")
public int getQuantity() {
return quantity;
}

@XmlAttribute
public String getId() {
return id;
}

@XmlValue
public String getValue() {
return value;
}

}
13 changes: 10 additions & 3 deletions src/main/java/de/flux/playground/deckcompare/dto/Deck.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@
import javax.xml.bind.annotation.XmlRootElement;

import lombok.Data;
import lombok.Getter;

@Data
@XmlRootElement
public class Deck {

@Getter(onMethod = @__(@XmlAttribute(name = "game")) )
private String id;
@Getter(onMethod = @__(@XmlElement(name = "section")) )
private List<Section> sections;
private String notes;

@XmlAttribute(name = "game")
public String getId() {
return id;
}

@XmlElement(name = "section")
public List<Section> getSections() {
return sections;
}

}
13 changes: 10 additions & 3 deletions src/main/java/de/flux/playground/deckcompare/dto/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
import javax.xml.bind.annotation.XmlType;

import lombok.Data;
import lombok.Getter;

@Data
@XmlType
public class Section {

@Getter(onMethod = @__(@XmlAttribute) )
private String name;
@Getter(onMethod = @__(@XmlElement(name = "card")) )
private List<Card> cards;

@XmlAttribute
public String getName() {
return name;
}

@XmlElement(name = "card")
public List<Card> getCards() {
return cards;
}

}

0 comments on commit d4b68cd

Please sign in to comment.