pushka icon indicating copy to clipboard operation
pushka copied to clipboard

Add converting to BSONDocument

Open andemi opened this issue 9 years ago • 8 comments

It would be great if there would be a way to convert json to BSONDocument (reactivemongo) and there would be a way to create custom handlers for some fields.

andemi avatar Sep 03 '16 17:09 andemi

Hi, @andemi !

Two questions:

  1. You need exactly BSONDocument, or ByteBuffer with BSON will be OK too?
  2. What do you mean when talking about "custom handlers for some fields"? This - case class User(@key("user_name") userName: String)?

fomkin avatar Sep 03 '16 18:09 fomkin

I think I hurried. After JSON we need validate data, so direct converting JSON to BSONDocument is redundant.

  1. BSONDocument http://reactivemongo.org/releases/0.11/api/index.html#reactivemongo.bson.BSONDocument
  2. No, validation or changing some data

andemi avatar Sep 05 '16 16:09 andemi

What means "validate"? It's needed for be sure thats email is email and age not 999? If it is, I suppose we can do it before converting to BSON. Anyway pushka.Ast to BSONDocument conversion will be lose data type precision: DateTime and Timestam became just Longs.

I have old plans about supporting various AST #3. It's next big thing in Pushka, so I planing to take this issue to work in few next months. I can take reactive-mongo as first external AST backend if you help me to realize requirements of reactive-mongo.

fomkin avatar Sep 06 '16 06:09 fomkin

It's needed for be sure thats email is email and age not 999? Yes, something like this.

Here some data types classes http://reactivemongo.org/releases/0.11/documentation/bson/typeclasses.html and http://reactivemongo.org/releases/0.11/documentation/json/overview.html

andemi avatar Sep 10 '16 07:09 andemi

So what "validation" means?

fomkin avatar Sep 11 '16 17:09 fomkin

For example, all data that comes from frontend must be checked

andemi avatar Sep 11 '16 20:09 andemi

Ok. "Yes, something like this" is in quote :) Such kind of validation is not Pushka's job. You can validate fields after case class was read.

fomkin avatar Sep 12 '16 09:09 fomkin

Waiting for #3.

fomkin avatar Sep 12 '16 09:09 fomkin