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
3bbacbd8
Commit
3bbacbd8
authored
Aug 18, 2018
by
Greg Messner
Browse files
Added toJsonString to be used by toString() methods in model classes (#234).
parent
b3b0867a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/utils/JacksonJson.java
View file @
3bbacbd8
...
...
@@ -218,4 +218,29 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
return
(
users
);
}
}
/**
* This class is used to create a thread-safe singleton instance of JacksonJson customized
* to be used by
*/
private
static
class
JacksonJsonSingletonHelper
{
private
static
final
JacksonJson
JACKSON_JSON
=
new
JacksonJson
();
static
{
JACKSON_JSON
.
objectMapper
.
setPropertyNamingStrategy
(
PropertyNamingStrategy
.
LOWER_CAMEL_CASE
);
JACKSON_JSON
.
objectMapper
.
setSerializationInclusion
(
Include
.
ALWAYS
);
}
}
/**
* Gets a the supplied object output as a formatted JSON string. Null properties will
* result in the value of the property being null. This is meant to be used for
* toString() implementations of GitLab4J classes.
*
* @param <T> the generics type for the provided object
* @param object the object to output as a JSON string
* @return a String containing the JSON for the specified object
*/
public
static
<
T
>
String
toJsonString
(
final
T
object
)
{
return
(
JacksonJsonSingletonHelper
.
JACKSON_JSON
.
marshal
(
object
));
}
}
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