title: How to convert a Java/Scala object to a Protocol Buffers message?
body: <p>I'm trying to convert a Java/Scala object into a Protocol Buffers message.</p>
  
  <p>My object is called <code>IDSNumber</code> and it has a <code>doubleValue</code> method which returns a <code>java.lang.Double</code>. I'm trying to get it to be converted automatically to a double during <a href="http://dozer.sourceforge.net/documentation/about.html" rel="nofollow">Dozer</a> object conversion.</p>
  
  <p>I've create a <a href="http://dozer.sourceforge.net/documentation/customconverter.html" rel="nofollow">Dozer Custom Converter</a> in Scala, here:</p>
  
  <pre><code>class IDSConverter extends DozerConverter[IDSNumber, java.lang.Double](classOf[IDSNumber], classOf[java.lang.Double]) {
      def convertTo(source: IDSNumber, destination: java.lang.Double): java.lang.Double = {
          source.doubleValue()
      }
      def convertFrom(source: java.lang.Double , destination: IDSNumber): IDSNumber = {
          new IDSNumber(source)
      }
  }
  </code></pre>
  
  <p>My Protocol Buffers message looks like the following (<code>shortFee</code> and <code>longFee</code> should be converted from the <code>IDSNumber</code> type):</p>
  
  <pre><code>message PerformanceSettingMessage {
      optional string                  displayCurrency           = 1;
      optional PeriodMessage           performancePeriod         = 2;
      optional int64                   conversionDate            = 3;
      optional BenchmarkOptionsMessage benchmarkOptions          = 4;
      optional string                  investmentStrategyMeaning = 5;
      optional double                  shortFee                  = 6;
      optional double                  longFee                   = 7;
  }
  </code></pre>
  
  <p>I try to use the converter in the following way:</p>
  
  <pre><code>    val longFee  = new IDSNumber(2.0)
      val shortFee = new IDSNumber(3.0)
      // newing up a real performance settings object with IDSNumbers for shortFee and longFee
      val performanceSettings = new PerformanceSettings(Currency.apply("$"), period, fj.data.Option.none(), fj.data.Option.none(), Investment_Weighted, shortFee, longFee)
  
      val mapper = new DozerBeanMapper() // new DozerMapper
      val idsConverter = new IDSConverter() // my IDSNumber converter
      mapper.setCustomConverters(java.util.Arrays.asList(idsConverter)) // make it use my IDSNumber converter
      val msg = mapper.map(performanceSettings, classOf[PerformanceSettingMessage]) // map my real performanceSettings object to my PerformanceSettingsMessage generated by Protocol Buffers
  </code></pre>
  
  <p>When I run the above code, <code>msg</code> has both <code>shortFee</code> and <code>longFee</code> set to <code>0.0</code>, instead of <code>2.0</code> and <code>3.0</code>. Any thoughts on what I'm doing wrong? Perhaps there's a better way (better library?) to convert these objects back and forth? Thanks!</p>