Skip to content

Instantly share code, notes, and snippets.

@stickfigure
Created April 17, 2012 04:46
Show Gist options
  • Save stickfigure/2403500 to your computer and use it in GitHub Desktop.
Save stickfigure/2403500 to your computer and use it in GitHub Desktop.
Jackson forgets @JSONVIEW when serializing through RefSerializer
public class RefSerializer extends JsonSerializer<Ref> {
@Override
public void serialize(Ref value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeObject(value.getValue());
}
}
@Path("/")
public class Run {
@GET
@Path("/thing")
@Produces(MediaType.APPLICATION_JSON)
@JsonView(ShouldShow.class)
public Ref<Thing> thing() {
return new Ref<Thing>(new Thing());
}
}
@JsonAutoDetect(fieldVisibility=Visibility.NONE, getterVisibility=Visibility.NONE, isGetterVisibility=Visibility.NONE)
public class Thing {
public class ShouldShow {}
public class ShouldNotShow extends ShouldShow {}
@JsonView(ShouldShow.class)
public String getBar() {
return "bar";
}
@JsonView(ShouldNotShow.class)
public String getFoo() {
return "foo";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment