12
votes

I am implementing a JSON API to be used by the Ember-Data REST Adapter.

The Ember-Data REST Adapter needs the JSON returned to follow this format:
http://jsonapi.org/format/

Ember-Data documentation:
http://emberjs.com/guides/models/the-rest-adapter/#toc_json-conventions

I know how to return JSON, say, using Spring MVC 3.2 / Jackson, that's not a problem. However, the JSON format must adhere to the format specified at jsonapi.org.

You can find a sample Django implementation if you google "ember data tastypie adapter" (sorry, not enough reputation points for a link [sic]), and rable also seems to have one.

Seems like jsonapi.org is a much referred to standard for several frameworks / languages.

Do I really need to implement this standard in Java myself?

Any help / pointers would be greatly appreciated.

Many thanks!

3
You will probably need to implement a custom Jackson serializer.CodeChimp
Yes, that is probably the only solution. I can't really find anything on a Java implementation. Seems like the new Spring MVC 3.2 HyperMedia format uses the Hypertext Application Language (HAL) [stateless.co/hal_specification.html], but this format seems to have been rejected by the jsonapi.org format [jsonapi.org/faq/]. If I get the time to write such a serialiser, I'll make sure to open source it....Sparkling Ideas
Serialiser + parser, actually :-) Needs complete CRUD operation set. Bummer. I think I'll have to put Ember Data on my nice-to-have list for now.Sparkling Ideas

3 Answers

0
votes

Genson appears to support JSONAPI format.

This is an example unit test:

JsonSerDeserSymetricTest.java

demonstrating deserialising a feed into classes. The classes include:

Feed.java - which has an id field Link.java - which has a href field

Genson will integrate with Spring MVC and Jersey for JAX-RS.

0
votes

There are some JSON:API implementations for Java:

  • Katharsis with Spring support but somehow dead for years
  • Crnk with Spring Boot 2 support is much more than just JSON:API serializer/deserializer
  • JSON:API for Spring HATEOAS based on Spring HATEOAS and Jackson with Boot 2 support, very lightweight but fresh

To clarify I have not used any of the libraries but if I have to I would try the last one from Kai Toedter unless I have the need for a very large system with JSON:API only so I can benefit from all the additional magic.

-1
votes

I think you can change the JSON property inside spring config file like this:

<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
    <list>
        <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
            <property name="prefixJson" value="true" />
        </bean>
    </list>
</property>
</bean>

You can take a look at Spring JSON Mapping also.

I hope this helped out !