Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
0a1d1eda
Commit
0a1d1eda
authored
Dec 16, 2018
by
Greg Messner
Browse files
Added compareJson() for comparing to objects of the same type.
parent
9997604a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/JsonUtils.java
View file @
0a1d1eda
...
...
@@ -65,7 +65,6 @@ public class JsonUtils {
return
(
jacksonJson
.
unmarshalMap
(
returnType
,
json
));
}
static
<
T
>
boolean
compareJson
(
T
apiObject
,
String
filename
)
throws
IOException
{
InputStreamReader
reader
=
new
InputStreamReader
(
TestGitLabApiBeans
.
class
.
getResourceAsStream
(
filename
));
...
...
@@ -88,7 +87,23 @@ public class JsonUtils {
return
(
sameJson
);
}
static
<
T
>
boolean
compareJson
(
T
apiObject
,
T
apiObject1
)
throws
IOException
{
String
objectJson
=
jacksonJson
.
marshal
(
apiObject
);
String
object1Json
=
jacksonJson
.
marshal
(
apiObject1
);
JsonNode
tree1
=
jacksonJson
.
getObjectMapper
().
readTree
(
objectJson
.
getBytes
());
JsonNode
tree2
=
jacksonJson
.
getObjectMapper
().
readTree
(
object1Json
.
getBytes
());
boolean
sameJson
=
tree1
.
equals
(
tree2
);
if
(!
sameJson
)
{
System
.
err
.
println
(
"JSON did not match:"
);
sortedDump
(
tree1
);
sortedDump
(
tree2
);
}
return
(
sameJson
);
}
static
void
sortedDump
(
final
JsonNode
node
)
throws
JsonProcessingException
{
final
Object
obj
=
jacksonJson
.
getObjectMapper
().
treeToValue
(
node
,
Object
.
class
);
System
.
err
.
println
(
jacksonJson
.
getObjectMapper
().
writeValueAsString
(
obj
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment