mardi 21 juin 2016

Ember Data with Spring's @RequestBody and Object Identities

My back-end is Spring (Boot) and I'm getting pretty far along with it and EmberJS. Hitting a slight snag now because when I create new records from Ember-Data, it posts the object with an identity:

{ "thing": {"name": "The Thing"} }

The default mapping that Jackson provides doesn't assume an identity so it can't map the JSON to the Entity. I have basically 3 options and I'm wondering if anyone else has been down this road and how they solved the problem.

Option 1 - Create DTO's that wrap my entities with an identity

public class Thing {
  private String name;
}

// use this for the @RequestBody
public class ThingDTO {
  private Thing thing;
}

Option 2 - Configure Jackson via a custom mapper to deserialize the JSON into my standard objects.

Option 3 - Configure an adapter/serializer for Ember-Data so that it doesn't include the object identity.




Aucun commentaire:

Enregistrer un commentaire