Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  
  package com.messners.gitlab.api;
  
  import java.io.Reader;
  import java.util.Date;
  
  import  javax.ws.rs.Produces;
  import  javax.ws.rs.core.MediaType;
 import  javax.ws.rs.ext.ContextResolver;
 import  javax.ws.rs.ext.Provider;
 
Jackson JSON Configuration and utility class.

Author(s):
Greg Messner <greg@messners.com>
 
 @Provider
 @Produces(MediaType.APPLICATION_JSON)
 public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResolver<ObjectMapper> {
 		
 	private final ObjectMapper objectMapper;
 
     public JacksonJson () {
 
 		
 		SimpleModule module = new SimpleModule("GitLabApiJsonModule"new Version(1, 0, 0, null));
 		module.addSerializer(Date.classnew JsonDateSerializer());
 	}
   
    
 
     @Override
     public ObjectMapper getContext (Class<?> objectType) {
         return ();
     }
    
    
    
Gets the ObjectMapper contained by this instance.

Returns:
the ObjectMapper contained by this instance
 
     public ObjectMapper getObjectMapper () {
     	return ();
     }
    
    
Unmarshal the JSON data on the specified Reader instance to an instance of the provided class.

Parameters:
returnType an instance of this type class will be returned
reader the Reader instance that contains the JSON data
Returns:
an instance of the provided class containing the parsed data from the Reader
Throws:
JsonParseException
JsonMappingException
IOException
 
 	public <T> T unmarshal (Class<T> returnTypeReader reader
 		ObjectMapper objectMapper = getContext(returnType);
 		return (objectMapper.readValue(reader,  returnType));	
 	}

Unmarshal the JSON data contained by the string and populate an instance of the provided returnType class.

Parameters:
returnType an instance of this type class will be returned
postData
Returns:
an instance of the provided class containing the parsed data from the string
Throws:
JsonParseException
JsonMappingException
IOException
	public <T> T unmarshal (Class<T> returnTypeString postData
		ObjectMapper objectMapper = getContext(returnType);
		return (objectMapper.readValue(postData,  returnType));	
	}


Marshals the supplied object out as a formatted JSON string.

Parameters:
object the object to output as a JSON string
Returns:
	public <T> String marshal (final T object) {
		if (object == null) {
			throw new IllegalArgumentException("object parameter is null");
		}
		String results = null;
		try {
			results = writer.writeValueAsString(object);
catch (JsonGenerationException e) {
			..println("JsonGenerationException, message=" + e.getMessage());
catch (JsonMappingException e) {
			..println("JsonMappingException, message=" + e.getMessage());
catch (IOException e) {
			..println("IOException, message=" + e.getMessage());
		}
		return (results);
	}


JsonSerializer for serializing ISO8601 formatted dates.
	public static class JsonDateSerializer extends JsonSerializer<Date> {
		public void serialize(java.util.Date dateJsonGenerator genSerializerProvider provider)
	            throws IOExceptionJsonProcessingException {
			String iso8601String = ISO8601.toString(date);
			gen.writeString(iso8601String);
		}
	}	
New to GrepCode? Check out our FAQ X