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
066705e9
Commit
066705e9
authored
Feb 25, 2014
by
Greg Messner
Browse files
Renamed JacksonJsonConfig to JacksonJson.
parent
e3d66245
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/messners/gitlab/api/GitLabApi.java
View file @
066705e9
...
@@ -177,5 +177,31 @@ public class GitLabApi {
...
@@ -177,5 +177,31 @@ public class GitLabApi {
}
}
return
(
response
.
getEntity
(
MergeRequest
.
class
));
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
));
}
}
}
src/main/java/com/messners/gitlab/api/GitLabApiClient.java
View file @
066705e9
...
@@ -50,7 +50,7 @@ public class GitLabApiClient {
...
@@ -50,7 +50,7 @@ public class GitLabApiClient {
this
.
privateToken
=
privateToken
;
this
.
privateToken
=
privateToken
;
clientConfig
=
new
DefaultClientConfig
();
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
(
ClientConfig
.
PROPERTY_FOLLOW_REDIRECTS
,
Boolean
.
TRUE
);
clientConfig
.
getFeatures
().
put
(
JSONConfiguration
.
FEATURE_POJO_MAPPING
,
Boolean
.
TRUE
);
clientConfig
.
getFeatures
().
put
(
JSONConfiguration
.
FEATURE_POJO_MAPPING
,
Boolean
.
TRUE
);
}
}
...
...
src/main/java/com/messners/gitlab/api/JacksonJson
Config
.java
→
src/main/java/com/messners/gitlab/api/JacksonJson.java
View file @
066705e9
package
com.messners.gitlab.api
;
package
com.messners.gitlab.api
;
import
java.io.IOException
;
import
java.io.Reader
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
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.JsonParseException
;
import
org.codehaus.jackson.map.JsonMappingException
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.PropertyNamingStrategy
;
import
org.codehaus.jackson.map.PropertyNamingStrategy
;
import
org.codehaus.jackson.map.SerializationConfig
;
import
org.codehaus.jackson.map.SerializationConfig
;
...
@@ -14,7 +19,7 @@ import org.codehaus.jackson.map.DeserializationConfig;
...
@@ -14,7 +19,7 @@ import org.codehaus.jackson.map.DeserializationConfig;
import
org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion
;
import
org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion
;
/**
/**
* Jackson JSON Configuration class
* Jackson JSON Configuration
and utility
class
.
*
*
* @author Greg Messner <greg@messners.com>
* @author Greg Messner <greg@messners.com>
*
*
...
@@ -22,11 +27,11 @@ import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
...
@@ -22,11 +27,11 @@ import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
@Provider
@Provider
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
class
JacksonJson
Config
implements
ContextResolver
<
ObjectMapper
>
{
public
class
JacksonJson
implements
ContextResolver
<
ObjectMapper
>
{
private
final
ObjectMapper
objectMapper
;
private
final
ObjectMapper
objectMapper
;
public
JacksonJson
Config
()
{
public
JacksonJson
()
{
objectMapper
=
new
ObjectMapper
();
objectMapper
=
new
ObjectMapper
();
objectMapper
.
setSerializationInclusion
(
Inclusion
.
NON_NULL
);
objectMapper
.
setSerializationInclusion
(
Inclusion
.
NON_NULL
);
...
@@ -36,14 +41,51 @@ public class JacksonJsonConfig implements ContextResolver<ObjectMapper> {
...
@@ -36,14 +41,51 @@ public class JacksonJsonConfig implements ContextResolver<ObjectMapper> {
objectMapper
.
configure
(
DeserializationConfig
.
Feature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
objectMapper
.
configure
(
DeserializationConfig
.
Feature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
objectMapper
.
configure
(
DeserializationConfig
.
Feature
.
READ_ENUMS_USING_TO_STRING
,
Boolean
.
TRUE
);
objectMapper
.
configure
(
DeserializationConfig
.
Feature
.
READ_ENUMS_USING_TO_STRING
,
Boolean
.
TRUE
);
}
}
/**
*
*/
@Override
@Override
public
ObjectMapper
getContext
(
Class
<?>
objectType
)
{
public
ObjectMapper
getContext
(
Class
<?>
objectType
)
{
return
(
objectMapper
);
return
(
objectMapper
);
}
}
/**
*
* @return
*/
public
ObjectMapper
getObjectMapper
()
{
public
ObjectMapper
getObjectMapper
()
{
return
(
objectMapper
);
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
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