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
066705e9
Commit
066705e9
authored
11 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Renamed JacksonJsonConfig to JacksonJson.
parent
e3d66245
main
5.0.x
5.0.x.jdk17
6.x
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main/java/com/messners/gitlab/api/GitLabApi.java
+26
-0
src/main/java/com/messners/gitlab/api/GitLabApi.java
src/main/java/com/messners/gitlab/api/GitLabApiClient.java
+1
-1
src/main/java/com/messners/gitlab/api/GitLabApiClient.java
src/main/java/com/messners/gitlab/api/JacksonJson.java
+46
-4
src/main/java/com/messners/gitlab/api/JacksonJson.java
with
73 additions
and
5 deletions
+73
-5
src/main/java/com/messners/gitlab/api/GitLabApi.java
+
26
-
0
View file @
066705e9
...
...
@@ -177,5 +177,31 @@ public class GitLabApi {
}
return
(
response
.
getEntity
(
MergeRequest
.
class
));
}
/**
* GET /projects/:id/repository/branches/:branch
*
* @param projectId
* @param branchName
* @return
* @throws IOException
*/
public
Branch
getBranch
(
Integer
projectId
,
String
branchName
)
throws
IOException
{
ClientResponse
response
=
apiClient
.
get
(
null
,
"projects"
,
projectId
,
"repository"
,
"branches"
,
branchName
);
return
(
response
.
getEntity
(
Branch
.
class
));
}
/**
* GET /users/:id
*
* @param userId
* @return
* @throws IOException
*/
public
User
getUser
(
int
userId
)
throws
IOException
{
ClientResponse
response
=
apiClient
.
get
(
null
,
"users"
,
userId
);
return
(
response
.
getEntity
(
User
.
class
));
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/messners/gitlab/api/GitLabApiClient.java
+
1
-
1
View file @
066705e9
...
...
@@ -50,7 +50,7 @@ public class GitLabApiClient {
this
.
privateToken
=
privateToken
;
clientConfig
=
new
DefaultClientConfig
();
clientConfig
.
getClasses
().
add
(
JacksonJson
Config
.
class
);
clientConfig
.
getClasses
().
add
(
JacksonJson
.
class
);
clientConfig
.
getFeatures
().
put
(
ClientConfig
.
PROPERTY_FOLLOW_REDIRECTS
,
Boolean
.
TRUE
);
clientConfig
.
getFeatures
().
put
(
JSONConfiguration
.
FEATURE_POJO_MAPPING
,
Boolean
.
TRUE
);
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/messners/gitlab/api/JacksonJson
Config
.java
→
src/main/java/com/messners/gitlab/api/JacksonJson.java
+
46
-
4
View file @
066705e9
package
com.messners.gitlab.api
;
import
java.io.IOException
;
import
java.io.Reader
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.ext.ContextResolver
;
import
javax.ws.rs.ext.Provider
;
import
org.codehaus.jackson.JsonParseException
;
import
org.codehaus.jackson.map.JsonMappingException
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.PropertyNamingStrategy
;
import
org.codehaus.jackson.map.SerializationConfig
;
...
...
@@ -14,7 +19,7 @@ import org.codehaus.jackson.map.DeserializationConfig;
import
org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion
;
/**
* Jackson JSON Configuration class
* Jackson JSON Configuration
and utility
class
.
*
* @author Greg Messner <greg@messners.com>
*
...
...
@@ -22,11 +27,11 @@ import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
@Provider
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
class
JacksonJson
Config
implements
ContextResolver
<
ObjectMapper
>
{
public
class
JacksonJson
implements
ContextResolver
<
ObjectMapper
>
{
private
final
ObjectMapper
objectMapper
;
public
JacksonJson
Config
()
{
public
JacksonJson
()
{
objectMapper
=
new
ObjectMapper
();
objectMapper
.
setSerializationInclusion
(
Inclusion
.
NON_NULL
);
...
...
@@ -36,14 +41,51 @@ public class JacksonJsonConfig implements ContextResolver<ObjectMapper> {
objectMapper
.
configure
(
DeserializationConfig
.
Feature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
objectMapper
.
configure
(
DeserializationConfig
.
Feature
.
READ_ENUMS_USING_TO_STRING
,
Boolean
.
TRUE
);
}
/**
*
*/
@Override
public
ObjectMapper
getContext
(
Class
<?>
objectType
)
{
return
(
objectMapper
);
}
/**
*
* @return
*/
public
ObjectMapper
getObjectMapper
()
{
return
(
objectMapper
);
}
/**
*
* @param returnType
* @param reader
* @return
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
public
<
T
>
T
unmarshall
(
Class
<
T
>
returnType
,
Reader
reader
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
ObjectMapper
objectMapper
=
getContext
(
returnType
);
return
(
objectMapper
.
readValue
(
reader
,
returnType
));
}
/**
*
* @param returnType
* @param postData
* @return
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
public
<
T
>
T
unmarshall
(
Class
<
T
>
returnType
,
String
postData
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
ObjectMapper
objectMapper
=
getContext
(
returnType
);
return
(
objectMapper
.
readValue
(
postData
,
returnType
));
}
}
\ 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