Buggy code:
@ Path ( "//{applicationtokenid}//{userTokenId}//user" ) @ Controller public class UserResource { private static final Logger log = LoggerFactory . getLogger ( UserResource . class ) ; UserService userService ; ObjectMapper mapper = new ObjectMapper ( ) ; @ Autowired public UserResource ( UserService userService ) { } @ POST @ Path ( "//" ) @ Consumes ( { MediaType . APPLICATION_JSON , MediaType . APPLICATION_XML } ) @ Produces ( { MediaType . APPLICATION_JSON , MediaType . APPLICATION_XML } ) public Response createUser ( @ PathParam ( "applicationtokenid" ) String applicationTokenId , @ PathParam ( "userTokenId" ) String userTokenId , String userXml , @ Context Request request ) { } private boolean isXmlContent ( String userXml ) { } @ POST @ Path ( "//changePassword//{username}" ) @ Consumes ( MediaType . APPLICATION_FORM_URLENCODED ) @ Produces ( MediaType . APPLICATION_XML ) public Response changePassword ( @ PathParam ( "applicationtokenid" ) String applicationTokenId , @ PathParam ( "userTokenId" ) String userTokenId , @ PathParam ( "username" ) String userName , String password ) { } @ GET @ Path ( "//{userId}" ) @ Produces ( { MediaType . APPLICATION_JSON , MediaType . APPLICATION_XML } ) public Response getUser ( @ PathParam ( "applicationtokenid" ) String applicationTokenId , @ PathParam ( "userTokenId" ) String userTokenId , @ PathParam ( "userId" ) String userId , @ Context Request req ) { } @ GET @ Path ( "//{userId}//roles" ) @ Produces ( MediaType . APPLICATION_JSON ) public Response getRoles ( @ PathParam ( "applicationtokenid" ) String applicationTokenId , @ PathParam ( "userTokenId" ) String userTokenId , @ PathParam ( "userId" ) String userId ) { } private MediaType findPreferedContentType ( Request req ) { } private MediaType findPreferedResponseType ( Request req ) { } @ POST @ Path ( "//{userId}//role" ) @ Consumes ( MediaType . APPLICATION_XML ) @ Produces ( MediaType . APPLICATION_XML ) public Response addRole ( @ PathParam ( "applicationtokenid" ) String applicationTokenId , @ PathParam ( "userTokenId" ) String userTokenId , @ PathParam ( "userId" ) String userId , String roleXml ) { } @ POST @ Path ( "//{userId}//role//" ) @ Consumes ( MediaType . APPLICATION_JSON ) @ Produces ( MediaType . APPLICATION_JSON ) public Response addRoleJson ( @ PathParam ( "applicationtokenid" ) String applicationTokenId , @ PathParam ( "userTokenId" ) String userTokenId , @ PathParam ( "userId" ) String userId , String roleJson ) { UserResource . log . trace ( "addRoleJson<seq2seq4repair_space>is<seq2seq4repair_space>called<seq2seq4repair_space>with<seq2seq4repair_space>userId={},<seq2seq4repair_space>roleXml<seq2seq4repair_space>{}" , userId , roleJson ) ; try { RoleRepresentationRequest roleRequest = RoleRepresentationRequest . fromJson ( roleJson ) ; RoleRepresentation roleRepresentation = userService . addUserRole ( applicationTokenId , userTokenId , userId , roleRequest ) ; <START_BUG> return Response . ok ( roleRepresentation . toXML ( ) ) . build ( ) ; <END_BUG> } catch ( IllegalArgumentException iae ) { UserResource . log . error ( "addRoleJson:<seq2seq4repair_space>Invalid<seq2seq4repair_space>json={},<seq2seq4repair_space>userId<seq2seq4repair_space>{}" , roleJson , userId , iae ) ; return Response . status ( BAD_REQUEST ) . build ( ) ; } catch ( IllegalStateException ise ) { UserResource . log . error ( "addRoleJson:<seq2seq4repair_space>IllegalStateException<seq2seq4repair_space>json={},<seq2seq4repair_space>userId<seq2seq4repair_space>{}" , roleJson , userId , ise ) ; return Response . status ( CONFLICT ) . build ( ) ; } catch ( RuntimeException e ) { UserResource . log . error ( "addRoleJson:<seq2seq4repair_space>RuntimeException<seq2seq4repair_space>json={},<seq2seq4repair_space>userId<seq2seq4repair_space>{}" , roleJson , userId , e ) ; return Response . status ( INTERNAL_SERVER_ERROR ) . build ( ) ; } } @ GET @ Path ( "//ping//pong" ) @ Produces ( MediaType . TEXT_HTML ) public Response ping ( ) { } protected String buildApplicationJson ( Application application ) { } protected String buildUserXml ( UserAggregate userAggregate ) { } }

Fix:
return Response . ok ( roleRepresentation . toJson ( ) ) . build ( ) ;