Giter VIP home page Giter VIP logo

Comments (5)

abr-egn avatar abr-egn commented on September 4, 2024 1

Having distinct structs is probably the best way to go there, thanks for clarifying!

from bson-rust.

abr-egn avatar abr-egn commented on September 4, 2024

Hi! Thanks for raising this - there's no particular reason that's lacking, we should definitely add it :) I've filed https://jira.mongodb.org/browse/RUST-1681 to track this. We'd also be happy to accept a PR if you'd like to implement it!

from bson-rust.

sunsided avatar sunsided commented on September 4, 2024

I took the liberty to give it a try in #421.

from bson-rust.

abr-egn avatar abr-egn commented on September 4, 2024

Sorry that I didn't notice this earlier - as @patrickfreed quite correctly points out, the implementation of Deserialize for ObjectId already accepts a hex string (#421 just passes through to that implementation), so this should work without an extra deserialize helper. Can you give more details about the error you're seeing?

from bson-rust.

pianocomposer321 avatar pianocomposer321 commented on September 4, 2024

Yes, so I realized this after opening the issue. The problem I was having wasn't actually related to this, I was just thinking that maybe doing this would fix it. I wanted to have the object ids represented with the ObjectId type in my code, and as a bson object id in mongodb, but as a string for the json serialization. The problem was that if I changed the serializer, it would serialize it as a string when interacting with mongodb as well, so it wouldn't store it as an ObjectId there either. I thought maybe having this feature would solve that, but now I don't think it would, because the issue is that it is serializing it the same for json and bson, when I don't want it to do that.

What I ended up doing is creating a new struct for just my json api that serializes to a hex string and keeping my main struct for interacting with mongodb the same. If there's a way to do this with a single struct by differentiating between serializing for json vs bson, I'd love to know about it. But, I think this issue can probably be closed.

from bson-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.