Modules such as json_field or jsonb allows entities to have fields holding arbitrary JSON data.
When retrieved through JSONAPI, theses fields' value is a string containing the data as encoded JSON.
A new enhancer could decode the string on the fly so the data would be a real JSON object inside the response payload.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | interdiff-2906753-13.txt | 2.88 KB | logickal |
| #13 | jsonapi-extras_JSONFieldEnhancer-2906753-13.patch | 2.36 KB | logickal |
| #12 | interdiff-2906753-12.txt | 516 bytes | logickal |
| #12 | jsonapi-extras_JSONFieldEnhancer-2906753-12.patch | 2.26 KB | logickal |
| #4 | interdiff-2906753-4.txt | 1.46 KB | garphy |
Comments
Comment #2
garphyFirst attempt of doing this.
Comment #4
garphyThis is an updated patch for 2.x branch.
Comment #6
garphyComment #7
e0ipsoKicking off tests.
Comment #8
logickal commentedWe're doing the exact same thing in a custom enhancer - +1 for including this functionality in the upstream module. One thing of note, at least in our case, the json could also be an array so for this to be one-size-fits-all, I'd suggest adding that to the getOutputJsonSchema.
Comment #9
logickal commented@garphy @e0ipso Another question - is there a general preference to using
\Symfony\Component\Serializer\SerializerInterfaceoverDrupal\Component\serialization\Json?Comment #10
simeI upgraded to the latest jsonapi_extras and the enhancers changed a bit - I got stuck on validator config. So I moved the my enhancer into a standalone module, so I could nurse it along and see how this issue progresses.
https://gist.github.com/simesy/fb44c48fcab0725b019b0fd6dc7e1fb2 in case anyone needs something urgently.
Comment #11
garphy@logickal, I chose to go with
SerializerInterfaceas it seemed to be the coherent with what jsonapi mostly uses itself but it seems that it also useJson::decode()directly in some places.@e0ipso, any opinion ?
Comment #12
logickal commentedHere's a quick re-roll to support arrays.
Comment #13
logickal commentedAnd for the sake of discussion, here is the code that we are running on our end in our custom enhancer, rolled onto the original patch.
Comment #14
e0ipsoThis is a c&p error.
I will fix this issue on commit. Thanks everyone for the contribution!
Comment #16
e0ipsoThanks for your relentless contributions.