1+ package wu.seal.jsontokotlin
2+
3+ import org.junit.Before
4+ import org.junit.Test
5+
6+ import org.junit.Assert.*
7+
8+ /* *
9+ *
10+ * Created by Seal.Wu on 2018/2/6.
11+ */
12+ class KotlinMakerTest {
13+ @Before
14+ fun setUp () {
15+ isTestModel = true
16+ }
17+
18+ @Test
19+ fun makeKotlinData () {
20+ val json1 = """ { "progr ammers": [
21+ { "isFirstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },
22+ { "firstName": "Jason", "lastName":"Hunter", "email": "bbbb" },
23+ { "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
24+ ],
25+ "aut_hors": [
26+ { "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
27+ { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
28+ { "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
29+ ],
30+ "musicians": [
31+ { "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
32+ { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
33+ ] } """
34+
35+ val json2 = """ {"123menu": {
36+ "i d": [1,23,34],
37+ "value":[],
38+ "popup": {
39+ "m#@!$#%$#^%*^&(*)*(_)+{|}{:enu_item": [
40+ {"value": "New", "onclick": "CreateNewDoc()"},
41+ {"value": "Open", "onclick": "OpenDoc()"},
42+ {"value": "Close", "onclick": "CloseDoc()"}
43+ ]}
44+ }}"""
45+
46+ println (" json1 ====>\n ${KotlinMaker (" Class1" , json1).makeKotlinData()} " )
47+ println (" json2 ====>\n ${KotlinMaker (" Class2" , json2).makeKotlinData()} " )
48+
49+ TestConfig .targetJsonConvertLib = TargetJsonConverter .Jackson
50+ TestConfig .isCommentOff = true
51+ TestConfig .isPropertiesVar = true
52+ TestConfig .isPropertyNullable = false
53+
54+ println (" ===========================================Change to Jackson json lib support========================================= " )
55+
56+ println (" json1 ====>\n ${KotlinMaker (" Class1" , json1).makeKotlinData()} " )
57+ println (" json2 ====>\n ${KotlinMaker (" Class2" , json2).makeKotlinData()} " )
58+
59+
60+ TestConfig .targetJsonConvertLib = TargetJsonConverter .FastJson
61+ TestConfig .isCommentOff = true
62+ TestConfig .isPropertiesVar = true
63+ TestConfig .isPropertyNullable = false
64+
65+ println (" ===========================================Change to FastJson json lib support========================================= " )
66+
67+ println (" json1 ====>\n ${KotlinMaker (" Class1" , json1).makeKotlinData()} " )
68+ println (" json2 ====>\n ${KotlinMaker (" Class2" , json2).makeKotlinData()} " )
69+
70+
71+
72+ TestConfig .targetJsonConvertLib = TargetJsonConverter .Gson
73+ TestConfig .isCommentOff = false
74+ TestConfig .isPropertiesVar = false
75+ TestConfig .isPropertyNullable = true
76+
77+ println (" ===========================================Change to Gson json lib support========================================= " )
78+
79+ println (" json1 ====>\n ${KotlinMaker (" Class1" , json1).makeKotlinData()} " )
80+ println (" json2 ====>\n ${KotlinMaker (" Class2" , json2).makeKotlinData()} " )
81+ }
82+
83+ }
0 commit comments