@Override
 public String getSerializationBodyFormat() {
   final HttpAdapter routerAdapter =
       (HttpAdapter) RemoteRailsConfig.getRouterAdapterByClass(this.getClass());
   if (routerAdapter == null || routerAdapter.getConfigurationsAsConfiguration("GET") == null) {
     return RemoteRailsConfig.getInstance().getDefaultRouterAdapter().getSuffix();
   }
   return routerAdapter.getConfigurationsAsConfiguration("POST").getBodyFormat();
 }
  @Override
  public String serialize() {
    String bodyFormat = getSerializationBodyFormat();
    SerializerBuilder builder = null;

    String recordSelector = HttpAdapter.createResponseWrangling(this).getRecordSelector();
    if (XML.equals(bodyFormat)) {
      builder = new XmlSerializer.XmlSerializerBuilder(recordSelector);
    } else if (JSON.equals(bodyFormat)) {
      builder = new JsonSerializer.JsonSerializerBuilder(recordSelector);
    } else if (FORM_ENCODED.equals(bodyFormat)) {
      builder = new FormEncodedSerializer.FormEncodedSerializerBuilder(recordSelector);
    }

    final RouterAdapter routerAdapter = RemoteRailsConfig.getRouterAdapterByClass(this.getClass());
    if (builder != null && routerAdapter != null) {

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("id"),
          "id");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("comments"),
          "comments");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("currency"),
          "currency");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("last_price"),
          "last_price");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("last_qty"),
          "last_qty");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("price"),
          "price");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("quantity"),
          "quantity");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("side"),
          "side");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("status"),
          "status");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("symbol"),
          "symbol");

      builder.addFieldMapping(
          ((HttpAdapter) routerAdapter)
              .getConfigurationsAsConfiguration("POST")
              .getResponseRemoteFieldName("transact_time"),
          "transact_time");

      return builder.create().serialize(this);
    } else {
      return super.serialize();
    }
  }
  public RemoteObject deserialize(String queryScope, Parser parser) {
    final RouterAdapter routerAdapter = RemoteRailsConfig.getRouterAdapterByClass(this.getClass());
    CapitalMarketsOrder object = new CapitalMarketsOrder();
    HttpAdapter.Configuration configuration = null;
    if ((routerAdapter != null) && (routerAdapter instanceof HttpAdapter)) {
      if (queryScope != null && !queryScope.isEmpty()) {
        configuration =
            ((HttpAdapter) routerAdapter).getScopedConfigurationsByNameAsConfiguration(queryScope);
      } else {
        configuration = ((HttpAdapter) routerAdapter).getConfigurationsAsConfiguration("GET");
      }
    }
    if (configuration != null) {

      try {

        object.id = parser.parse(configuration.getResponseRemoteFieldName("id"), ObjectId.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.comments =
            parser.parse(configuration.getResponseRemoteFieldName("comments"), String.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.currency =
            parser.parse(configuration.getResponseRemoteFieldName("currency"), String.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.lastPrice =
            parser.parse(configuration.getResponseRemoteFieldName("last_price"), Float.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.lastQty =
            parser.parse(configuration.getResponseRemoteFieldName("last_qty"), Integer.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.price = parser.parse(configuration.getResponseRemoteFieldName("price"), Float.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.quantity =
            parser.parse(configuration.getResponseRemoteFieldName("quantity"), Integer.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.side = parser.parse(configuration.getResponseRemoteFieldName("side"), String.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.status =
            parser.parse(configuration.getResponseRemoteFieldName("status"), String.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.symbol =
            parser.parse(configuration.getResponseRemoteFieldName("symbol"), String.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

      try {

        object.transactTime =
            parser.parse(configuration.getResponseRemoteFieldName("transact_time"), String.class);

      } catch (PathNotFoundException e) {
        log.info("Unable to deserialize field: " + e.getMessage());
      }

    } else {
      // Default to use gson deserializer
      String json = "";
      if (parser instanceof JsonParser) {
        json = ((JsonParser) parser).getRootElement().toString();
      }

      object = (CapitalMarketsOrder) Utilities.transformJsonToObject(json, this.getClass());
    }

    return object;
  }