rest - Return an array with a single element using Gson and HAL (Hypertext Application Language) -
i'm having problems using halarious (java library hal specification) , gson serialise list of links in _links section single element. array serialized object instead of being array single link.
example: i'm getting is:
{ "year": 2008, "_embedded": { "items": { "_links": { "self": { "href": "/first_item" } } } } }
instead of:
{ "year": 2008, "_embedded": { "items": { "_links": { "self": [ { "href": "/first_item" } ] } } } }
i solved same problem _embedded section can't solve links section.
thanks
i solved using workaround. dont' use @hallink surrogate ad hoc class contains hierarchy , instance named "_links".
so using list of custom href objects when has single link i'll receive expected self attribute list single element.
after hal documentation (http://stateless.co/hal_specification.html) says: "if you're unsure whether link should singular, assume multiple" , http://blog.stateless.co/post/13296666138/json-linking-with-hal "where relation may potentially have multiple links sharing same key value should array of link objects". in way won't break consumers having them deal either json array or object.
Comments
Post a Comment