doctrine-json-odm: Add option to don't store #type along json data

Hello!

What about adding Deserialization type in the app codebase instead of storing it in the database?

Something like:

/**
  * @ORM\Column(type="json_document", class="App\Address", options={"jsonb": true})
  */
public $foo;

class could also be in options if it’s easier to manage. It’s a bit like doctrine @Embedded.

My concern is that having classname stored in DB is hard to maintain as a migration strategy has to be established on each namespace change.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

I like the idea, however, it won’t work with nested entities of different types. What might work is some kind of mapper. So instead of #type you store #mapKey (or whatever) and in the annotation you can specify something along the lines of

typeMapping={"foobar": "App\Foobar", "otherkey": "App\Other"}

It would be also compatible with the existing solution so it’s totally opt-in.

Sure but you need to write custom code to (de)serialize your data. Having it done by this library out of the box would be nice (that’s what https://github.com/goodwix/doctrine-json-odm does).

What do you think about by typeMapping solution? If that would solve your problem (and there are a few thumb ups so probably it would for others), why not make a PR? 😄

You are likely already aware, but a fork of this library says it has moved the metadata out of the field: https://github.com/goodwix/doctrine-json-odm

Unfortunately the commits are not well-organised, so there is not a specific commit where they implemented this.

But there is a limitation with this approach: currently JSON ODM allows to store very variable data (mixed). With this approach, it’s not possible anymore.