0

Using Spring, how can I receive the following POST request properly so that I can return a result?

public ResponseEnvelope sendHalfMap(GameID gameID, PlayerID playerID) throws Exception
  {
    java.util.List<HalfMapNode> mapNodes = MapGenerator.generator();
    HalfMap halfMapMessageBody = new HalfMap(playerID.getID(), mapNodes);

    URL halfMapUrl = new URL(baseUrl, "game/" + gameID.getID() + "/halfmap");

    RestTemplate restTemplate = getRestTemplate();
    ResponseEnvelope requestResult = (ResponseEnvelope)restTemplate.postForObject(halfMapUrl.toURI(), halfMapMessageBody, ResponseEnvelope.class);

    return requestResult;
  }
herecy
  • 55
  • 1
  • 8

1 Answers1

1

The issue is seen in the exception message:

Main.NewMapNode does not have a no-arg default constructor.

If the class NewMapNode does not have a default, no-argument constructor, the Spring MVC framework will not be able to create the JAXB context for the NewMapNode and therefore fails. If it not possible to create a default, no-argument constructor for that class, see this SO answer for how to create a customer XmlAdapter.

Justin Albano
  • 3,809
  • 2
  • 24
  • 51