Commit 066705e9 authored by Greg Messner's avatar Greg Messner
Browse files

Renamed JacksonJsonConfig to JacksonJson.

parent e3d66245
...@@ -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));
}
} }
...@@ -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(JacksonJsonConfig.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);
} }
......
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 JacksonJsonConfig implements ContextResolver<ObjectMapper> { public class JacksonJson implements ContextResolver<ObjectMapper> {
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
public JacksonJsonConfig () { 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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment