-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
66 lines (39 loc) · 1.83 KB
/
Solution.java
File metadata and controls
66 lines (39 loc) · 1.83 KB
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
//And he laid hold on the dragon, that old serpent, which is the Devil, and Satan, and bound him a thousand years (Revelation 20:2)
public class Solution {
public static void main(String[] args) throws IOException {
Cat cat = new Cat();
cat.name = "Murka";
cat.age = 5;
cat.weight = 3;
StringWriter writer = new StringWriter();
convertToJSON(writer, cat);
System.out.println(writer.toString());
}
public static void convertToJSON(StringWriter writer, Object object) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(writer, object);
}
@JsonAutoDetect
public static class Cat {
@JsonProperty("wildAnimal")
public String name;
@JsonIgnore
public int age;
@JsonProperty("over")
public int weight;
Cat() {
}
}
}
/*
Вторая сериализация в JSON
НЕОБХОДИМО: подключенные библиотеки Jackson Core, Bind и Annotation версии 2.6.1
Расставь JSON аннотации так, чтобы результат работы метода main был следующим
{"wildAnimal":"Murka","over":3}
Требования:
1. Поле name класса Cat должно быть отмечено аннотацией JsonProperty.
2. Поле age класса Cat должно быть отмечено аннотацией JsonIgnore.
3. Поле weight класса Cat должно быть отмечено аннотацией JsonProperty.
4. Значение (value) аннотации JsonProperty у поля name должно быть равно "wildAnimal".
5. Значение (value) аннотации JsonProperty у поля weight должно быть равно "over".
*/