3
3
import java .io .BufferedReader ;
4
4
import java .io .IOException ;
5
5
import java .io .InputStreamReader ;
6
+ import java .io .Reader ;
6
7
import java .util .List ;
7
8
import java .util .Map ;
8
9
@@ -23,26 +24,56 @@ public class JsonUtils {
23
24
jacksonJson .getObjectMapper ().configure (SerializationFeature .ORDER_MAP_ENTRIES_BY_KEYS , true );
24
25
jacksonJson .getObjectMapper ().configure (MapperFeature .SORT_PROPERTIES_ALPHABETICALLY , true );
25
26
}
27
+
26
28
29
+ static <T > T unmarshalResource (Class <T > returnType , String filename ) throws JsonParseException , JsonMappingException , IOException {
30
+ InputStreamReader reader = new InputStreamReader (TestGitLabApiBeans .class .getResourceAsStream (filename ));
31
+ return (jacksonJson .unmarshal (returnType , reader ));
32
+ }
27
33
28
- static <T > T unmarshal (Class <T > returnType , String filename ) throws JsonParseException , JsonMappingException , IOException {
29
- InputStreamReader reader = new InputStreamReader (GitLabApi .class .getResourceAsStream (filename ));
34
+ static <T > List <T > unmarshalResourceList (Class <T > returnType , String filename ) throws JsonParseException , JsonMappingException , IOException {
35
+ InputStreamReader reader = new InputStreamReader (TestGitLabApiBeans .class .getResourceAsStream (filename ));
36
+ return (JsonUtils .unmarshalList (returnType , reader ));
37
+ }
38
+
39
+ static <T > Map <String , T > unmarshalResourceMap (Class <T > returnType , String filename ) throws JsonParseException , JsonMappingException , IOException {
40
+ InputStreamReader reader = new InputStreamReader (TestGitLabApiBeans .class .getResourceAsStream (filename ));
41
+ return (jacksonJson .unmarshalMap (returnType , reader ));
42
+ }
43
+
44
+ static <T > T unmarshal (Class <T > returnType , Reader reader ) throws JsonParseException , JsonMappingException , IOException {
30
45
return (jacksonJson .unmarshal (returnType , reader ));
31
46
}
32
47
33
- static <T > List <T > unmarshalList (Class <T > returnType , String filename ) throws JsonParseException , JsonMappingException , IOException {
34
- InputStreamReader reader = new InputStreamReader (GitLabApi .class .getResourceAsStream (filename ));
48
+ static <T > T unmarshal (Class <T > returnType , String json ) throws JsonParseException , JsonMappingException , IOException {
49
+ return (jacksonJson .unmarshal (returnType , json ));
50
+ }
51
+
52
+ static <T > List <T > unmarshalList (Class <T > returnType , Reader reader ) throws JsonParseException , JsonMappingException , IOException {
35
53
return (jacksonJson .unmarshalList (returnType , reader ));
36
54
}
37
55
38
- static <T > Map <String , T > unmarshalMap (Class <T > returnType , String filename ) throws JsonParseException , JsonMappingException , IOException {
39
- InputStreamReader reader = new InputStreamReader (GitLabApi .class .getResourceAsStream (filename ));
56
+ static <T > List <T > unmarshalList (Class <T > returnType , String json ) throws JsonParseException , JsonMappingException , IOException {
57
+ return (jacksonJson .unmarshalList (returnType , json ));
58
+ }
59
+
60
+ static <T > Map <String , T > unmarshalMap (Class <T > returnType , Reader reader ) throws JsonParseException , JsonMappingException , IOException {
40
61
return (jacksonJson .unmarshalMap (returnType , reader ));
41
62
}
42
63
64
+ static <T > Map <String , T > unmarshalMap (Class <T > returnType , String json ) throws JsonParseException , JsonMappingException , IOException {
65
+ return (jacksonJson .unmarshalMap (returnType , json ));
66
+ }
67
+
68
+
69
+
43
70
static <T > boolean compareJson (T apiObject , String filename ) throws IOException {
71
+ InputStreamReader reader = new InputStreamReader (TestGitLabApiBeans .class .getResourceAsStream (filename ));
72
+ return (compareJson (apiObject , reader ));
73
+ }
74
+
75
+ static <T > boolean compareJson (T apiObject , InputStreamReader reader ) throws IOException {
44
76
45
- InputStreamReader reader = new InputStreamReader (GitLabApi .class .getResourceAsStream (filename ));
46
77
String objectJson = jacksonJson .marshal (apiObject );
47
78
JsonNode tree1 = jacksonJson .getObjectMapper ().readTree (objectJson .getBytes ());
48
79
JsonNode tree2 = jacksonJson .getObjectMapper ().readTree (reader );
@@ -57,10 +88,11 @@ static <T> boolean compareJson(T apiObject, String filename) throws IOException
57
88
return (sameJson );
58
89
}
59
90
91
+
60
92
static void sortedDump (final JsonNode node ) throws JsonProcessingException {
61
93
final Object obj = jacksonJson .getObjectMapper ().treeToValue (node , Object .class );
62
- System .out .println (jacksonJson .getObjectMapper ().writeValueAsString (obj ));
63
- System .out .flush ();
94
+ System .err .println (jacksonJson .getObjectMapper ().writeValueAsString (obj ));
95
+ System .err .flush ();
64
96
}
65
97
66
98
static String readResource (String filename ) throws IOException {
0 commit comments