Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Define custom Jackson annotation using @JacksonAnnotationsInside

You can define Custom Jackson Annotation using @JacksonAnnotationsInside. @JacksonAnnotationsInside is a meta-annotation used to create a "combo-annotations" by having a container annotation, which needs to be annotated with this annotation as well as all annotations it 'contains'.


Find the below working application.


import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE)
@JsonIgnoreProperties(ignoreUnknown = true)
public @interface AppJSON {




public class Employee {
private Integer id;
private String name;
private Integer age;

public Integer getId() {
return id;

public void setId(Integer id) { = id;

public String getName() {
return name;

public void setName(String name) { = name;

public Integer getAge() {
return age;

public void setAge(Integer age) {
this.age = age;



import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class App {

public static void main(String args[]) throws JsonProcessingException {
Employee emp = new Employee();

String result = new ObjectMapper().writeValueAsString(emp);



Previous                                                    Next                                                    Home

This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Define custom Jackson annotation using @JacksonAnnotationsInside


Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription