title: Problems with Spring Boot returning Map with own object as key
body: <p>I have a problem with <code>Spring Boot</code>.
  I am making a REST application, and I have a service that returns a Map(Share, Integer)</p>
  
  <p>Share is a class written by me:</p>
  
  <pre><code>public class Share {
  
      private String ticker;
      private String name;
      private Double value;
  
      public Share() {
          super();
      }
  
      public Share(String ticker, String name, Double value) {
          super();
          this.ticker = ticker;
          this.name = name;
          this.value = value;
      }
  
      public String getTicker() {
          return ticker;
      }
  
      public void setTicker(String ticker) {
          this.ticker = ticker;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public Double getValue() {
          return value;
      }
  
      public void setValue(Double value) {
          this.value = value;
      }
  
      @Override
      public int hashCode() {
         final int prime = 31;
         int result = 1;
          result = prime * result + ((ticker == null) ? 0 : ticker.hashCode());
          return result;
      }
  
      @Override
      public boolean equals(Object obj) {
          if (this == obj)
              return true;
          if (obj == null)
              return false;
          if (getClass() != obj.getClass())
              return false;
          Share other = (Share) obj;
          if (ticker == null) {
              if (other.ticker != null)
                  return false;
              } else if (!ticker.equals(other.ticker))
                  return false;
          return true;
      } 
  
      @Override
      public String toString() {
          return "Share [ticker=" + ticker + ", name=" + name + ", value=" + value + "]";
      }
  }
  </code></pre>
  
  <p>And the @RestController is:</p>
  
  <pre><code>public class ShareController {
  
      @Autowired
      private ShareBussines shareBussines;
  
      @RequestMapping("/getShare/{ticker}")
      public Share getShare(@PathVariable("ticker") String ticker) throws BrokerNotFoundException, BrokerArgumentException, BrokerGeneralException {
          return shareBussines.getShare(ticker);
      }
  
      @RequestMapping(value="/buyShares", method=RequestMethod.POST)
      public Map&lt;Share, Integer&gt; buyShares(@RequestBody Map&lt;String,Double&gt; sharesToBuy) throws BrokerGeneralException, BrokerArgumentException, BrokerInsufficientStockException {
          return shareBussines.buyShares(sharesToBuy);
      }
  
  }
  </code></pre>
  
  <p>The problem is when I call the service from Postman.</p>
  
  <p>The result is:</p>
  
  <pre><code>{
      "Share [ticker=AMZN, name=Amazon, value=259.32126508258295]": 1,
      "Share [ticker=GOOGL, name=Google, value=249.35339337497606]": 1,
      "Share [ticker=FB, name=Facebook, value=181.15005639608364]": 55
  }
  </code></pre>
  
  <p>The Map key is <code>share.toString()</code>... I want the key to be the share JSON.
  I try to remove the toString method from Share class, but the result was:</p>
  
  <pre><code>{
      "Share@1eb87f": 1,
      "Share@40d9fab": 1,
      "Share@8db": 54
  }
  </code></pre>
  
  <p>It is using the Object's toString().</p>
  
  <p>Thank you for your advice.</p>