Skip to content

Add some sort of extension point in CBORParser for pluggable custom-tag support #581

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cowtowncoder opened this issue Apr 30, 2025 · 2 comments

Comments

@cowtowncoder
Copy link
Member

(note: inspired by FasterXML/jackson-core#1428)

Since tag system in CBOR is extensible, users may well want to use custom tags.
Although there is a very bare-bones accessibility mechanism with CBORParser, basically 2 methods:

   public int getCurrentTag() {
        return _tagValues.getFirstTag();
    }

    public TagList getCurrentTags() {
        return _tagValues;
    }

it would be good to have some sort of mechanism (callback(s)?) to allow some automation of handling -- to give low-level access to CBORParser state upon encountering tags (either ones not supported by Jackson CBOR module, or maybe all).

I don't know exactly how that should look like so help would be appreciated.

@honhimW
Copy link

honhimW commented May 6, 2025

@cowtowncoder

I have currently succeeded in using jackson-cbor to handle serialization/deserialization with custom tags. I'm not sure if my implementation is sufficient, but it works exactly as I expected🎉.

From my experience, during serialization, I can continue using the JsonSerializer interface, so the main issues are concentrated in the Parser part.

  • As I mentioned in another issue(​​Question:​​ Delegating a parser/generator like ParserMinimalBase or ParserBase jackson-core#1428), ParserMinimalBase#_updateToken(JsonToken) require reflection;
  • For composite structures, they are converted to TreeNode first and then further transformed into the target type, and a context is needed to store the result. In such, I can reuse most of the functionality without having to process each token individually;
  • If possible, use JsonDeserializer for deserialization, but it seems unlikely?
  • Perhaps a Visitor-like approach could be added for callbacks, such as how to handle when a certain tag is encountered?

Note: My approach may not be optimal, but I hope it can be helpful to you.
Refs:
Code
Curtom Tags

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

No branches or pull requests

2 participants