質問するログイン新規登録

回答編集履歴

1

追記

2017/06/21 00:55

投稿

root_jp
root_jp

スコア4666

answer CHANGED
@@ -11,4 +11,73 @@
11
11
  別の変数名にマッピングしたければ、アノテーションで指定すればできます。
12
12
 
13
13
  [http://qiita.com/opengl-8080/items/b613b9b3bc5d796c840c](http://qiita.com/opengl-8080/items/b613b9b3bc5d796c840c)
14
- [http://www.nilab.info/z3/20150617_01_java_json_object_mapping_by_jackson.html](http://www.nilab.info/z3/20150617_01_java_json_object_mapping_by_jackson.html)
14
+ [http://www.nilab.info/z3/20150617_01_java_json_object_mapping_by_jackson.html](http://www.nilab.info/z3/20150617_01_java_json_object_mapping_by_jackson.html)
15
+
16
+ ###追記
17
+ 1つ目のクラス
18
+ ```java
19
+ import java.util.List;
20
+
21
+ import com.fasterxml.jackson.annotation.JsonProperty;
22
+
23
+ public class JavaObjectClass {
24
+
25
+ @JsonProperty("@id")
26
+ private String id;
27
+
28
+ @JsonProperty("@name")
29
+ private String name;
30
+
31
+ @JsonProperty("CLASS")
32
+ private List<InnerObject> classList;
33
+
34
+ public JavaObjectClass() {
35
+ }
36
+
37
+ public JavaObjectClass(String id, String name) {
38
+ this.id = id;
39
+ this.name = name;
40
+ }
41
+
42
+ //アクセッサ
43
+ public void setId(String id) {this.id = id;}
44
+ public String getId() {return id;}
45
+ public void setName(String name) {this.name = name;}
46
+ public String getName() {return name;}
47
+ public void setClassList(List<InnerObject> classList) { this.classList = classList; }
48
+ public List<InnerObject> getClassList() { return classList; }
49
+ }
50
+ ```
51
+ 2つ目のクラス
52
+ ```java
53
+ import com.fasterxml.jackson.annotation.JsonIgnore;
54
+ import com.fasterxml.jackson.annotation.JsonProperty;
55
+
56
+ public class InnerObject {
57
+ @JsonProperty("@code")
58
+ private String code;
59
+ @JsonProperty("@name")
60
+ private String name;
61
+ @JsonProperty("@level")
62
+ private String level;
63
+ @JsonIgnore
64
+ private String parentCode;
65
+
66
+ public InnerObject() {
67
+ }
68
+
69
+ public InnerObject(String code, String name, String level, String parentCode) {
70
+ this.code = code;
71
+ this.name = name;
72
+ this.level = level;
73
+ }
74
+
75
+ //アクセッサ
76
+ public String getCode() {return code;}
77
+ public void setCode(String code) {this.code = code;}
78
+ public String getName() {return name;}
79
+ public void setName(String name) {this.name = name;}
80
+ public String getLevel() {return level;}
81
+ public void setLevel(String level) {this.level = level;}
82
+ }
83
+ ```