Skip to content

jackmatt2/JsonResponse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@JsonResponse & @JsonMixin

Jackson mixin support for spring controllers using annotations.

Example

Simply annotate your @RequestMapping method with @JsonResponse and pass an array of @JsonMixin's to apply.

	@RequestMapping("/customers/summary")
	@JsonResponse(mixins = {
			@JsonMixin(target=Customer.class, mixin=Customer.SummaryMixin.class),
			@JsonMixin(target=Address.class, mixin=Address.SummaryMixin.class)
	})
	public @ResponseBody List<Customer> listSummary()
	{
		return data;
	}

Servlet Configuration

Modify your spring configuration as follows:

	<mvc:annotation-driven>
		<mvc:message-converters>
			<beans:bean class="au.id.jackmatthews.jsonresponse.JsonResponseAwareJsonMessageConverter" />
		</mvc:message-converters>
	</mvc:annotation-driven>
	
	<beans:bean class="au.id.jackmatthews.jsonresponse.JsonResponseSupportFactoryBean" />

Which Project?

The project comes as a Spring MVC application with an example mapping, you can import the projects into STS and test the generated WAR file on your server.

Too add the code to your own project all you need is the src/main/java folder from the core project and the src/main/java folder from either project spring3jackson1 or spring4jackson2. You also need to make the spring configuration chages above. You can delete the au.id.jackmatthews.jsonresponse.example package completely.

You will aso need to add the guava maven dependency to your project:

                <dependency>
                        <groupId>com.google.guava</groupId>
                        <artifactId>guava</artifactId>
                        <version>13.0.1</version>
                </dependency> 

core - required

spring3jackson1 - for Spring 3.x and Jackson 1.9.x

spring4jackson2 - for Spring 4.x and Jackson 2.x

You will have to do a mix and match of the source code if you are using a different configuration (say Spring 3.x > and Jackson 2.x)

Acknowledgements

The project is based on the @ResponseView project by martypitt https://github.com/martypitt/JsonViewExample

About

Jackson Mixin Support for Spring Controllers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages