aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/json/CardSerializer.java
blob: 7eaa0cbc26363292f39aa5370c623e6b6b33c9f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package eu.equalparts.cardbase.json;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import eu.equalparts.cardbase.card.Card;

public class CardSerializer extends JsonSerializer<Card> {
	@Override
	public void serialize(Card card, JsonGenerator jGen, SerializerProvider serializerProvider) throws IOException  {
		jGen.writeStartObject();

		if (card.name.get() != null) {
			jGen.writeStringField("name", card.name.get());
		} else {
			jGen.writeNullField("name");
		}

		if (card.layout.get() != null) {
			jGen.writeStringField("layout", card.layout.get());
		} else {
			jGen.writeNullField("layout");
		}

		if (card.manaCost.get() != null) {
			jGen.writeStringField("manaCost", card.manaCost.get());
		} else {
			jGen.writeNullField("manaCost");
		}

		if (card.cmc.get() != null) {
			jGen.writeNumberField("cmc", card.cmc.get());
		} else {
			jGen.writeNullField("cmc");
		}

		if (card.type.get() != null) {
			jGen.writeStringField("type", card.type.get());
		} else {
			jGen.writeNullField("type");
		}

		if (card.rarity.get() != null) {
			jGen.writeStringField("rarity", card.rarity.get());
		} else {
			jGen.writeNullField("rarity");
		}

		if (card.text.get() != null) {
			jGen.writeStringField("text", card.text.get());
		} else {
			jGen.writeNullField("text");
		}

		if (card.flavor.get() != null) {
			jGen.writeStringField("flavor", card.flavor.get());
		} else {
			jGen.writeNullField("flavor");
		}

		if (card.artist.get() != null) {
			jGen.writeStringField("artist", card.artist.get());
		} else {
			jGen.writeNullField("artist");
		}

		if (card.number.get() != null) {
			jGen.writeStringField("number", card.number.get());
		} else {
			jGen.writeNullField("number");
		}

		if (card.power.get() != null) {
			jGen.writeStringField("power", card.power.get());
		} else {
			jGen.writeNullField("power");
		}

		if (card.toughness.get() != null) {
			jGen.writeStringField("toughness", card.toughness.get());
		} else {
			jGen.writeNullField("toughness");
		}

		if (card.loyalty.get() != null) {
			jGen.writeNumberField("loyalty", card.loyalty.get());
		} else {
			jGen.writeNullField("loyalty");
		}

		if (card.multiverseid.get() != null) {
			jGen.writeNumberField("multiverseid", card.multiverseid.get());
		} else {
			jGen.writeNullField("multiverseid");
		}

		if (card.imageName.get() != null) {
			jGen.writeStringField("imageName", card.imageName.get());
		} else {
			jGen.writeNullField("imageName");
		}

		if (card.setCode.get() != null) {
			jGen.writeStringField("setCode", card.setCode.get());
		} else {
			jGen.writeNullField("setCode");
		}

		jGen.writeEndObject();
	}
}