title: Return BigDecimal fields as JSON String values in Java
body: <p>I have a <code>Get API</code> which returns a <code>JSON</code>. The format expected is:</p>
  
  <pre><code>{
     "value1": "123.00",
     "value2": "23.00"
  }
  </code></pre>
  
  <p>These values are <code>BigDecimal</code> in the object:</p>
  
  <pre><code>public class Result{
      BigDecimal value1;
      BigDecimal value2;
      // getters and setters
  }
  </code></pre>
  
  <p>Now, when the request is made, I create the <code>Result</code> object and populate these values as <code>BigDecimal</code>, create a list and return. The response I received is:</p>
  
  <pre><code>{
     "value1": 123.00,
     "value2": 23.00
  }
  </code></pre>
  
  <p>The values are correct but are not strings. How can I make them strings?</p>
  
  <p>I know we can convert <code>BigDecimal</code> to <code>String</code> but I have object with BigDecimal fields only and I can't populate String values to it.</p>
  
  <p>Finally, this is how the list is made:</p>
  
  <pre><code>List&lt;MyObj&gt; obj = Arrays.stream(myObj).collect(Collectors.toList());
  
      Result result = new Result();
  
      obj.forEach(t -&gt; t.mergeToResult(result));  // mergeToResults does all the population like result.setValue1(new BigDecimal(123.00))
  
      return result;
  </code></pre>