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
c88bd0ad
Commit
c88bd0ad
authored
Feb 25, 2014
by
Greg Messner
Browse files
Added marshal() and renamed unmarshall() to unmarshal().
parent
066705e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/messners/gitlab/api/JacksonJson.java
View file @
c88bd0ad
...
@@ -10,9 +10,11 @@ import javax.ws.rs.core.MediaType;
...
@@ -10,9 +10,11 @@ import javax.ws.rs.core.MediaType;
import
javax.ws.rs.ext.ContextResolver
;
import
javax.ws.rs.ext.ContextResolver
;
import
javax.ws.rs.ext.Provider
;
import
javax.ws.rs.ext.Provider
;
import
org.codehaus.jackson.JsonGenerationException
;
import
org.codehaus.jackson.JsonParseException
;
import
org.codehaus.jackson.JsonParseException
;
import
org.codehaus.jackson.map.JsonMappingException
;
import
org.codehaus.jackson.map.JsonMappingException
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.ObjectWriter
;
import
org.codehaus.jackson.map.PropertyNamingStrategy
;
import
org.codehaus.jackson.map.PropertyNamingStrategy
;
import
org.codehaus.jackson.map.SerializationConfig
;
import
org.codehaus.jackson.map.SerializationConfig
;
import
org.codehaus.jackson.map.DeserializationConfig
;
import
org.codehaus.jackson.map.DeserializationConfig
;
...
@@ -68,7 +70,7 @@ public class JacksonJson implements ContextResolver<ObjectMapper> {
...
@@ -68,7 +70,7 @@ public class JacksonJson implements ContextResolver<ObjectMapper> {
* @throws JsonMappingException
* @throws JsonMappingException
* @throws IOException
* @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
{
throws
JsonParseException
,
JsonMappingException
,
IOException
{
ObjectMapper
objectMapper
=
getContext
(
returnType
);
ObjectMapper
objectMapper
=
getContext
(
returnType
);
return
(
objectMapper
.
readValue
(
reader
,
returnType
));
return
(
objectMapper
.
readValue
(
reader
,
returnType
));
...
@@ -83,9 +85,38 @@ public class JacksonJson implements ContextResolver<ObjectMapper> {
...
@@ -83,9 +85,38 @@ public class JacksonJson implements ContextResolver<ObjectMapper> {
* @throws JsonMappingException
* @throws JsonMappingException
* @throws IOException
* @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
{
throws
JsonParseException
,
JsonMappingException
,
IOException
{
ObjectMapper
objectMapper
=
getContext
(
returnType
);
ObjectMapper
objectMapper
=
getContext
(
returnType
);
return
(
objectMapper
.
readValue
(
postData
,
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
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