The Json:API requires recommends compound attribute names to be hyphened (like first-name)
...
{
"type": "people",
"id": "9",
"attributes": {
"first-name": "Foo",
"last-name": "Bar",
}
...
In Java hyphened attribute names are not valid identifiers.
I'm using Katharsis 2.0.1 to build a JSON:API based service backend within spring-boot 1.3.0. My calling/consuming frontend app is build with Ember 2.0 and ember-data.
Unfortunately Katharsis doesn't seem to convert compound attribute names in Java to hypehened attribute names in Json.
This is a result Katharsis generates for a resource GET /api/customers
{
"data": [
{
"type": "customers",
"id": "1",
"attributes": {
"cpn": "-1234567",
"firstName": "John",
},
...
But it should be "first-name": "John"
Am I missing some configuration or how do I tell Katharsis do hyphen attributes?
Thanks!
Following @Ethans advice I stick with camelCase attributes in Katharsis.io and let Ember override the attribute names.
In Ember the JSONAPISerializer supports all cases in the sense that it provides hooks that are easily overridden. The docs for keyForAttribute and keyForRelationship shows examples of how to customize keys.
In my case I had to implement the following serializer class:
// app/application/serializer.js or app/serializers/application.js
import Ember from 'ember';
import DS from 'ember-data';
export default DS.JSONAPISerializer.extend({
keyForAttribute: function(attr, method) {
return Ember.String.camelize(attr);
},
keyForRelationship: function(key, relationship, method) {
return Ember.String.camelize(key);
}
});