struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johannes Geppert (Resolved) (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (WW-3629) Provide a JSON Content Handler based on Jackson Lib
Date Fri, 18 Nov 2011 18:05:01 GMT

     [ https://issues.apache.org/jira/browse/WW-3629?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Johannes Geppert resolved WW-3629.
----------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0.15
    
> Provide a JSON Content Handler based on Jackson Lib
> ---------------------------------------------------
>
>                 Key: WW-3629
>                 URL: https://issues.apache.org/jira/browse/WW-3629
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - REST
>            Reporter: Johannes Geppert
>            Assignee: Johannes Geppert
>            Priority: Minor
>              Labels: handler, json
>             Fix For: 2.0.15
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> Provide a JSON Content Handler based on Jackson Lib:
> http://jackson.codehaus.org/
> Jackson is a:
>     Streaming (reading, writing)
>     FAST (measured to be faster than any other Java json parser and data binder)
>     Powerful (full data binding for common JDK classes as well as any Java bean class,
Collection, Map or Enum)
>     Zero-dependency (does not rely on other packages beyond JDK)
>     Open Source (LGPL or AL)
>     Fully conformant
>     Extremely configurable
> JSON processor (JSON parser + JSON generator) written in Java. Beyond basic JSON reading/writing
(parsing, generating), it also offers full node-based Tree Model, as well as full OJM (Object/Json
Mapper) data binding functionality.
> A Content Handler can look like this:
> import java.io.IOException;
> import java.io.Writer;
> import org.codehaus.jackson.JsonGenerationException;
> import org.codehaus.jackson.map.JsonMappingException;
> import org.codehaus.jackson.map.ObjectMapper;
> import org.codehaus.jackson.map.SerializationConfig.Feature;
> public class JsonContentHandler implements ContentHandler {
> 	public void fromObject(Object object, Writer writer) {
> 		try {
> 			ObjectMapper objectMapper = new ObjectMapper();
> 			objectMapper.configure(Feature.WRITE_NULL_MAP_VALUES, false);
> 			objectMapper.writeValue(writer, object);
> 		} catch (JsonGenerationException e) {
> 			e.printStackTrace();
> 		} catch (JsonMappingException e) {
> 			e.printStackTrace();
> 		} catch (IOException e) {
> 			e.printStackTrace();
> 		}
> 	}
> 	public String getContentType() {
> 		return "application/json";
> 	}
> 	public String getExtension() {
> 		return "json";
> 	}
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message