code: private Entity<String> serialize(Object obj, String contentType) throws ClientErrorException {
          if (contentType.startsWith("application/json")) {
              try {
                  return Entity.json(jsonMarshaller.serialize(obj));
              } catch (JsonMarshallingException e) {
                  String msg = "Failed marshalling object to JSON data for sending to server: "+e.getMessage();
  //                throw new ClientErrorException(Response.Status.BAD_REQUEST, e);
                  throw new BadRequestServiceException(
                          new RestFaultInfo("BadRequest", Blame.CLIENT,
                                  msg, ""+ ErrorCodes.Client.MARSHALLING_FAILED.getCode(),
                                  null,
                                  Retry.no(), Retry.no(),
                                  Response.Status.BAD_REQUEST.getStatusCode(),
                                  Response.Status.BAD_REQUEST.getReasonPhrase()
                          ), e
                  );
              }
          } else {
              String msg = "Content type \"" + contentType + "\" is not supported.";
  //            throw new NotSupportedException(msg);
              throw new BadRequestServiceException(
                      new RestFaultInfo("BadRequest", Blame.CLIENT,
                              msg, ""+ ErrorCodes.Client.UNSUPPORTED_TECHNOLOGY.getCode(),
                              null,
                              Retry.no(), Retry.no(),
                              Response.Status.BAD_REQUEST.getStatusCode(),
                              Response.Status.BAD_REQUEST.getReasonPhrase()
                      )
              );
          }
      }
docs: Serialize the given Java object into string entity according the given
  Content-Type (only JSON is supported for now).
  This data is then sent to the server.