Skip to content

Registering CustomUnmarshaler with context #699

@pgeiem

Description

@pgeiem

Is your feature request related to a problem? Please describe.

The possibility of registering some CustomUnmarshaler is really useful for handling interface types that are used in multiple places or for externally declared types.
Unfortunately, and contrary to all unmarshaling options, there is not an option to get context. For example BytesUnmarshaler has InterfaceUnmarshalerContext, InterfaceUnmarshaler has InterfaceUnmarshalerContext...

Describe the solution you'd like

It would be nice to add an option function equivalent to CustomUnmarshaler with context support, such as: func CustomUnmarshaler[T any](unmarshaler func(*T, context.Context, []byte) error) DecodeOption

This would register such unmarshaler in the decoder in a new customUnmarshalerMapContext which will be used in priority compared to the current customUnmarshalerMap accordingly to the priority order of others unmarshaller with or without context.

If such an addition is welcome, I can contribute it. Just le me know.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions