Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
c88bd0ad
Commit
c88bd0ad
authored
11 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Added marshal() and renamed unmarshall() to unmarshal().
parent
066705e9
main
5.0.x
5.0.x.jdk17
6.x
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/messners/gitlab/api/JacksonJson.java
+33
-2
src/main/java/com/messners/gitlab/api/JacksonJson.java
with
33 additions
and
2 deletions
+33
-2
src/main/java/com/messners/gitlab/api/JacksonJson.java
+
33
-
2
View file @
c88bd0ad
...
...
@@ -10,9 +10,11 @@ import javax.ws.rs.core.MediaType;
import
javax.ws.rs.ext.ContextResolver
;
import
javax.ws.rs.ext.Provider
;
import
org.codehaus.jackson.JsonGenerationException
;
import
org.codehaus.jackson.JsonParseException
;
import
org.codehaus.jackson.map.JsonMappingException
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.ObjectWriter
;
import
org.codehaus.jackson.map.PropertyNamingStrategy
;
import
org.codehaus.jackson.map.SerializationConfig
;
import
org.codehaus.jackson.map.DeserializationConfig
;
...
...
@@ -68,7 +70,7 @@ public class JacksonJson implements ContextResolver<ObjectMapper> {
* @throws JsonMappingException
* @throws IOException
*/
public
<
T
>
T
unmarshal
l
(
Class
<
T
>
returnType
,
Reader
reader
)
public
<
T
>
T
unmarshal
(
Class
<
T
>
returnType
,
Reader
reader
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
ObjectMapper
objectMapper
=
getContext
(
returnType
);
return
(
objectMapper
.
readValue
(
reader
,
returnType
));
...
...
@@ -83,9 +85,38 @@ public class JacksonJson implements ContextResolver<ObjectMapper> {
* @throws JsonMappingException
* @throws IOException
*/
public
<
T
>
T
unmarshal
l
(
Class
<
T
>
returnType
,
String
postData
)
public
<
T
>
T
unmarshal
(
Class
<
T
>
returnType
,
String
postData
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
ObjectMapper
objectMapper
=
getContext
(
returnType
);
return
(
objectMapper
.
readValue
(
postData
,
returnType
));
}
/**
* Marshals the supplied object out as a formatted JSON string.
*
* @param object
* @return
*/
public
<
T
>
String
marshal
(
final
T
object
)
{
if
(
object
==
null
)
{
throw
new
IllegalArgumentException
(
"object parameter is null"
);
}
ObjectWriter
writer
=
objectMapper
.
writer
().
withDefaultPrettyPrinter
();
String
results
=
null
;
try
{
results
=
writer
.
writeValueAsString
(
object
);
}
catch
(
JsonGenerationException
e
)
{
System
.
err
.
println
(
"JsonGenerationException, message="
+
e
.
getMessage
());
}
catch
(
JsonMappingException
e
)
{
e
.
printStackTrace
();
System
.
err
.
println
(
"JsonMappingException, message="
+
e
.
getMessage
());
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"IOException, message="
+
e
.
getMessage
());
}
return
(
results
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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
Menu
Explore
Projects
Groups
Snippets