Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Can't register a custom converter #1550

Closed
sebastiannm opened this issue Sep 29, 2021 · 4 comments 路 Fixed by #1100
Closed

馃悰 Can't register a custom converter #1550

sebastiannm opened this issue Sep 29, 2021 · 4 comments 路 Fixed by #1100

Comments

@sebastiannm
Copy link

Fiber version
2.19.0

Issue description
Hi, I'm using the Mongodb Driver and when using QueryParser, I get an error saying that the type "primitive.ObjectID" is unknown. This is not specific to Fiber because others frameworks have the same problem, but other frameworks allow to register a custom Converter to fix the issue.
Ex: https://githubmemory.com/repo/kataras/iris/issues/1671

But in fiber, schema is inside internal, so I can't use it from my code

Code snippet

package main

import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/internal/schema"
"go.mongodb.org/mongo-driver/bson/primitive"
)

func main() {
  app := fiber.New()

 schema.NewDecoder().RegisterConverter(primitive.ObjectID{}, func(value string) reflect.Value {
		id, err := primitive.ObjectIDFromHex(value)
		fmt.Println("id", id)
		if err != nil {
			return reflect.Value{}
		}
		return reflect.ValueOf(id)
  })

  log.Fatal(app.Listen(":3000"))
}
@welcome
Copy link

welcome bot commented Sep 29, 2021

Thanks for opening your first issue here! 馃帀 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@ReneWerner87 ReneWerner87 linked a pull request Oct 1, 2021 that will close this issue
@ReneWerner87
Copy link
Member

with #1100 you can define custom converters

@ReneWerner87
Copy link
Member

its in the next release

@ReneWerner87
Copy link
Member

https://github.com/gofiber/fiber/releases/tag/v2.20.0
you can use
https://docs.gofiber.io/api/ctx#setparserdecoder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants