Skip to content

Commit e252f3c

Browse files
authored
key of the bottomless pit& great chain in his hand
And I saw an angel come down from heaven, having the key of the bottomless pit and a great chain in his hand. (Revelation 20:1)
1 parent 05ae53a commit e252f3c

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
//And I saw an angel come down from heaven, having the key of the bottomless pit and a great chain in his hand. (Revelation 20:1)
3+
4+
package com.javarush.task.task33.task3301;
5+
6+
import java.io.IOException;
7+
import java.io.StringWriter;
8+
import java.util.ArrayList;
9+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
10+
import com.fasterxml.jackson.annotation.JsonSubTypes;
11+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
12+
import com.fasterxml.jackson.databind.ObjectMapper;
13+
14+
15+
/*
16+
Первая сериализация в JSON
17+
*/
18+
public class Solution {
19+
public static void main(String[] args) throws IOException {
20+
Cat cat = new Cat();
21+
cat.name = "Murka";
22+
cat.age = 5;
23+
cat.weight = 3;
24+
25+
Dog dog = new Dog();
26+
dog.name = "Killer";
27+
dog.age = 8;
28+
dog.owner = "Bill Jeferson";
29+
30+
ArrayList<Pet> pets = new ArrayList<>();
31+
pets.add(cat);
32+
pets.add(dog);
33+
34+
StringWriter writer = new StringWriter();
35+
convertToJSON(writer, pets);
36+
System.out.println(writer.toString());
37+
}
38+
39+
public static void convertToJSON(StringWriter writer, Object object) throws IOException {
40+
ObjectMapper mapper = new ObjectMapper();
41+
mapper.writeValue(writer, object);
42+
}
43+
44+
@JsonAutoDetect
45+
public static class Pet {
46+
public String name;
47+
Pet () {}
48+
}
49+
50+
@JsonAutoDetect
51+
public static class Cat extends Pet {
52+
Cat (){}
53+
public int age;
54+
public int weight;
55+
}
56+
57+
@JsonAutoDetect
58+
public static class Dog extends Pet {
59+
public int age;
60+
public String owner;
61+
public Dog () {}
62+
}
63+
}
64+
65+
/*
66+
Первая сериализация в JSON
67+
68+
НЕОБХОДИМО: подключенные библиотеки Jackson Core, Bind и Annotation версии 2.6.1
69+
70+
71+
72+
1) В программе не выполнено основное требование к сериализации в JSON.
73+
74+
Найди ошибку и исправь.
75+
76+
2) Расставь правильно JSON аннотации у классов.
77+
78+
Все данные должны сериализоваться.
79+
80+
81+
82+
83+
84+
Требования:
85+
86+
1. Класс Pet должен быть помечен как готовый к сериализации в JSON.
87+
88+
2. Класс Cat должен быть помечен как готовый к сериализации в JSON.
89+
90+
3. Класс Dog должен быть помечен как готовый к сериализации в JSON.
91+
92+
4. Все данные у классов Pet, Cat, Dog должны сериализоваться.
93+
*/

0 commit comments

Comments
 (0)