This works with Jackson 2 (at least):
@Controller
public class YourController {
@RequestMapping(..)
public @ResponseBody Json get() {
return new Json("{ \"attr\" : \"value\" }");
}
}
class Json {
private final String value;
public Json(String value) {
this.value = value;
}
@JsonValue
@JsonRawValue
public String value() {
return value;
}
}
Not particularly pretty but works. I only wish Spring supported this:
@RequestMapping(..)
public @JsonRawValue @ResponseBody String get() {
// ...
}